There are already plenty of guides that explain the particular steps of getting Github on your machine. However, I had difficulty time trying to set it up for the first time. After several failed attempts at getting set up with GitHub Pages, I vowed that if I ever successfully set it up, I’d write a blog. Fortunately, I did eventually figure it out. Being a man of my words, here if the blog. 🙂 Don’t be scared if it did not work the first time. We will have things up and running .
Not being able to use Git in 2014 is a crime punishable by death. Hopefully by the end of this post you will be exonerated. So let’s get started.
What is Github?
Get this right, Github is not a development tool. GitHub is a web-based hosting service for software development projects that use the Git revision control system. It manages changes to a project without overwriting any part of that project. Why use something Git? Say you and a team mate are both updating a script on the same project. You make your changes, save them, and upload them back to the project. Mission complete. Hold your horses. Your coworker is also working on the same script as you at the same time. After a long day of head banging and Googling, one of you is about to go home having your work overwritten and erased.
Version control application like Git keeps that from happening. You and your team mate can each upload your revisions to the same script, and Git will save both copies. You can later merge your changes together without losing any work. Now you can all go home smiling. You can even revert to an earlier version at any time, because Git keeps a “snapshot” of every change ever made. It has completely changed the way we work.
The GitHub site has extensive documentation on getting started, and if you’re not a fan of using the command line, the official GitHub apps for Mac and Windows are great. It is one of the best revision control systems that I have used. I use Github to manage and store some of my code on the cloud. Best of all, its all FREE. I mean who doesn’t like free stuff. :-). Thanks to Github, I can now access my code no matter where I am. So let’s go through the basics.
Step 1: Sign Up for GitHub
This is the first and the easiest part of setting up GitHub. You will need to create a Github account if you haven’t already. This is straight forward. Keep your email close; we will be using it again in a few.
Step 2: Download & Install
You will need to download and Install Git for Windows, Mac or Linux. If you are on Windows or Mac, all you need to do is download and run the installer. For Linux users we will need to write some commands in terminal. So what are you waiting for, you should have opened terminal already.
2.1: Ubuntu, Debian and derived systems
Type the following commands in terminal to install git.
sudo apt-get install git
2.2: Ubuntu, Debian and derived systems
A windows version of Git can be found on the msysgit Project site. The URL to this webpage is listed below. This website also describes the installation process.
2.3: Confirm if Github is installed
Open Command prompt in windows and terminal in linux and type
If you successfully installed git, you will see something close to this. In my case i have version 184.108.40.206 installed.
if you have come this far with no issues, give yourself a pat on the back or better yet; buy me coffee 🙂
Step 3: User Configuration
Configure your user and email for Git via the following command. Type the following in Terminal. Remember to replace the Name and Email address with yours. The email address should be the one you signed in with. Put your user name in “userName” and your eMail address in “firstname.lastname@example.org”
git config --global user.name "userName"
git config --global user.email "email@example.com"
To check your Git settings, type the following in terminal.
git config --list
If you we are together, you should see the username and email address you entered.
All Git settings are described under the following link: git-config manual page
Step 4: SSH Keys(Optional)
“SSH uses public-key cryptography to authenticate the remote computer and allow it to authenticate the user, if necessary. There are several ways to use SSH; one is to use automatically generated public-private key pairs to simply encrypt a network connection, and then use password authentication to log on.”
An SSH key basically lets your computer uniquely identify itself when it connects to servers. If Github is aware of the key your computer is using, you won’t have to enter your Github username/password every time you connect.
Check for pre-existing SSH keys on your computer
Let’s see if your computer has one or more keys already installed:
Open terminal and navigate to the SSH directory by typing:
If you get the response “No such file or directory”, go to Generating a new SSH Key.
Otherwise, you’ll need to backup and remove your existing SSH keys.
Backup and remove your existing SSH keys.
cp id_rsa* key_backup
Generating a new SSH key
Now we’ll create a new SSH key to use with Github.
ssh-keygen -t rsa -C "firstname.lastname@example.org"
When it asks you to enter a file name in which to save the key, just press return/enter (leave the prompt blank).
You will then be asked to enter a passphrase and confirm it. Don’t make this blank, and don’t make it an easily guessable. This prevents someone from easily acquiring and using your SSH key to impersonate you. Don’t worry, we are almost done.
Press return/enter after each time you’ve entered your selected passphrase. You won’t see the characters or bullets, the cursor will stay in the same spot as if you aren’t typing.
If you make an error entering your password one of the times, just press return and it will prompt you to try again.
Once you’ve successfully set your passphrase, the terminal will report that your key has been saved and show you some cool art.
Step 5: Add Your SSH Key to Github
In order for your computer to access Github without you having to enter your username/password all the time, Github needs to know the contents of the SSH key you just generated. The following code to copy the key to your clipboard so don’t worry if you cannot see the Key.
sudo apt-get install xclip
Now we need to copy the Key. To do so, type the following in terminal.
xclip -sel clip < ~/.ssh/id_rsa.pub
Alternatively, using your favourite text editor, you can open the ~/.ssh/id_rsa.pub file and copy the contents of the file manually.
Now we’ll add your key to Github:
- Visit your account settings.
- Click Add SSH key.
- Enter a descriptive title for the computer you’re currently on, e.g. “Work iMac” into the Title field.
- Paste your key into the Key field (it has already been copied to your clipboard).
- Click Add Key.
- Enter your Github password.
Step 6: Testing Everything Out.
Now let’s test if everything worked. To do so we will need to SSH Github.
In terminal, type:
ssh -T email@example.com
Congratulations! Home Run.
You are now ready to create a repository which we will do that in another post. My bed is calling. All code and no sleep makes Tom a dull boy. Goodbye for now. 🙂