Here is my quick guide on setting up a new GitHub repository on an iMac adding files and syncing with a repository. Read the GitHub 101 if you are a beginner. Read my BitBucket guide here.
Why
Using git allows you to make backups, use code versioning, rollback code, use multiple development machines/have multiple users, auto merging code etc.
Github can be cheaper, more flexible and offer more features than something like Dropbox.
How
Create an account at GitHub and Login ( https://github.com/login ).
Don’t forget to set up Two Factor Authentication for extra security.
Login to GitHub (signup for a free account if need be).
Enter your Two Factor Authentication code every time you login.
Before you can read or write to your Git repository you need to set up a link between your computer (Mac) and GitHub by Setting up a Secure SSH Key with GitHub. About SSH.
If you have read any of my guides on setting up servers (e.g The quickest way to setup a scalable development IDE and web server, How to buy a new domain and SSL cert from NameCheap, a Server from Digital Ocean and configure it or Connecting to an AWS EC2 Ubuntu instance with Cloud 9 IDE as user ubuntu and root ) you will be familiar with SSH keys.
You can check your existing SSH Keys by typing the following.
Follow this GitHub guide on creating a new SSH key to use with GitHub.
I found I had to do the following in the Mac terminal to get this to work.
You can now add your SSH key to GitHub.
You can then add your public key to https://github.com/settings/keys
Add the SSH Key.
You can then test the SSH connection to GitHub.
At first, I tried this but got an error.
This is what I got when I added my SSH Key to my GitHub account. This worked for me (this updated my known_hosts file).
Tip: Don’t forget to save adding your SSH Key to GitHub
If you need help contact GitHub.
GitHub Pricing
GitHub offers free public repository pricing or $7 a month for unlimited personal repositories for personal use. Bitbucket is the Atlassian owned alternative to GitHub, they have free repositories for up to 5 users with 1TB.
Read my Setting up BitBucket on an iMac and creating a project guide.
Read on the differences between GitHub and BitBucket.
Create your first test public Repository.
Load https://www.github.com and click Start a Project, or go to https://github.com/new
To specify a Readme file and an ignore file if need be (we can do this later). You will need to be a paid Git member to create private repositories.
When your repository is created it will be ready to upload files: https://github.com/SimonFearby/testgitproject001
Creating a local folder
Create a local folder for the repository etc.
Liking the remote repository to the local folder.
First, we need to initialize git locally by typing the following.
Now we can add the remote “origin” repository to the local repo.
We can now see connected remote repositories by typing the following
Syncing (Pulling) the Repository
Generally, you want to pull all files from the remote repository after you create it (and the readme file).
This worked 🙂
Pulling, Pushing, Branches and Forking.
You can read more about pulling, pushing, branches and forking here.
This course helped me https://www.udemy.com/learn-android/
Adding your first local file(s) to the repository
Adding all files to the new directory.
Adding a single file:
Here is an example of adding a new file.
Set your default commit username (help)
Set your default commit email address (help).
Double-check config here
You will need to use vim to insert then save changes. I like the nano text editor better so I am changing the default editor.
Setting your default as nano (and not vim)
nano (and not vim)
Submitting (pushing) changes
The changes have been pushed (merged)
Adding another file.
This is how I added another single file locally and pushed to the remote (origin) server
Now we have two new public files in a repository and locally.
README.md and markdown
Now we need to make the README.MD file look nice and reflect the changes.
More info in markdown formatting here, here, here and here. Here is a good markdown table generator.
I made some changes (see) and pushed to the repository (origin).
My local README.md markdown changes
This is what is looks like on GitHub after I commit and push
You can use pages on GitHub with markdown to create versioned documentation and help.
Commit and check the git status frequently
It is strongly advisable to frequently commit files (to a staging/not master repository) and check local it status for any issues. Commit as frequently as you remember.
You can push or delete changes if need be.
Adding many subfolders and many files.
Let’s say you have just added three subfolders (iOS Project Code (12 files), Android Projet Code (1255 items) and a Windows Desktop Project Code (.NET) folder (27 items) and you want to add them all to the remote repository (origin).
Now we need to add the 1,294 files to the local repository.
We can simply type the following to tell git we want it to manage all the local files.
Now you can merge the files top remote repository (origin).
Don’t forget to updates your README.md file with changes.
fyi: GitHub may take a minute or two to show changes.
Ignoring local files
You may want to ignore local files or folders. In your git folder type. I like to ignore all files with “secret” in the filename.
AWS recommend you ignore secret keys and logs to prevent inadvertent account access via sharing secret keys.
You can find other things to ignore here. You can setup global ignore list by reading this.
You can see I have created a few secret files and new thirdnewfile.txt (and added it to git) and committed and pushed and the secret files remain local (they will remain local while they match the ignored list).
GitHub view.
Local Git View
GitHub Desktop Application
I checked out the GitHub Desktop application at https://desktop.github.com/.
The downloaded compressed file.
I extracted and copied the app to the Applications folder.
Now I logged into to the application.
Much respect to GitHub for integrating Two Factor Authentication into the login.
Unfortunately, GitHub Desktop thinks I have zero repositories (I have 9 repositories when I log in via the web using the same email address). I contacted support on Twitter but have not had a response yet?
I was able to clone the repository I made via the command line earlier or add a local repository.
I added a new text file (afileaddedwithgithubdesktop.txt) to the folder and GitHub Desktop noticed this new file straight away. I added this file to the repository.
I pushed all local changes to the origin/remote master repository.
All local changes were merged with the remote origin master (I could never do this with Atlassian’s SourceTree application).
Conclusion
Now I can sync up my projects that to GitHub repositories from the terminal and GitHub Desktop application and benefit from the features of git (backups, versioning, rollbacks, multiple machines/multiple users, auto merging etc).
Next
I will add how to pull a repository to a $5 month Digital Ocean and or AWS (Ubuntu) VM.
Read my Setting up BitBucket on an iMac and creating a project guide.
Git repositories on Raspberry Pi’s.
Related guides
Setting up a development environment on Digital Ocean 14.04
https://www.digitalocean.com/community/tutorials/how-to-install-git-on-ubuntu-14-04
Tips and Troubleshooting
GitHub has a good tips page here. I had @GitHubHelp pro-actively contact me for support on Twitter. Contact GitHub here.
How to add all local files and commit all local files.
I hope this is helpful to someone.
P.S Don’t edit live code, use GitHub.
Agile Project Management
Read my blog post on developing software and staying on track here.
I highly recommend you follow Dmitri Iarandine at http://joinagile.com/ (Agile Coach, Trainer, Host of Lean and Mean Agile). Podcast. Author of GET HIRED as SCRUM MASTER).
Dmitri can be found here too.
Soundcloud (Lean and Mean Agile Podcast):
https://soundcloud.com/user-364782318
iTunes:
https://itunes.apple.com/au/podcast/lean-and-mean-agile-podcast/id1269551866
YouTube:
https://www.youtube.com/channel/UC00OZqfM9VmznEOTVzrQQxw
Twitter:
http://twitter.com/iarandine
Udemy:
https://www.udemy.com/agile-coaching-101/
Amazon:
https://www.amazon.com/author/iarandine
Donate and make this blog better
Ask a question or recommend an article
[contact-form-7 id=”30″ title=”Ask a Question”]
v1.7 added info on agile and staying on track,