A Voyage Of Discovery - Git - Starting A New

Written by Ashley Broadley on Sunday, 21st August 2011 at 10:23

As a continuation of my "A Voyage of Discovery" series, I'm also going to delve into the power that is Git. Git is what's known as a Distributed Version Control System, similar to Mercurial. As I mentioned in a previous post back in September last year, Git is something that I've not had a chance to really get to learn about. So I'm taking this opportunity to document the things that I learn about, mainly for my own reference.

For this mini series, I'm going to be using Github to begin with, then I'll move on to setting up a remote git server and using that as the centralised location for our repos. Also, for reference, I think it's worth noting that I'm running Ubuntu 10.10 on a laptop. To complement one of my Phing articles, I'm going to be using the build files in the examples there as the file I want to track.

Is It Running Yet?

Git installation differ depending on what OS you're running, but I choose to do it via the command line. So to install Git I run:

ashley@laptop:~$ sudo apt-get install git-core git-doc git-gui

Let the package manager install everything and you're done. It's that simple.

Git-What?

Github. It's an online git repository hosting website. It's free for personal and open-source projects! So first of all you should sign up there. 

Ok, so once you're signed up with Github, we can now set up our SSH Key so we can actually commiunicate with our repository. To start you need to have an SSH Public and Private Key. Thankfully, these are pretty easy to create. On the CLI, run the following and just press enter when it asks you about the location to save:

ashley@laptop:~$ ssh-keygen -t rsa -C "me@example.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ashley/.ssh/id_rsa): 

It'll now ask for a passphrase. You don't need to enter one, but I highly recommend it. 

Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ashley/.ssh/id_rsa.
Your public key has been saved in /home/ashley/.ssh/id_rsa.pub.
The key fingerprint is:
04:a6:0b:df:52:ab:d4:9d:43:01:57:6d:62:29:85:c8 me@example.com
The key's randomart image is:
+--[ RSA 2048]----+
|     .+oo+oo     |
|     oEoo.+ o    |
|  . . . oo o     |
|   o = = .       |
|    = + S        |
|   . o   .       |
|    .            |
|                 |
|                 |
+-----------------+

What you need to do now is add your public key to Github. 

So, to add your public key to Github, simply open the file '~/.ssh/id_rsa.pub' in your favourite editor and copy the contents to your clipboard. Now navigate your browser to Github and login. From here click on Account Settings -> SSH Public Keys -> Add another public key. In the dialog that appears, give the key a name, for example "Me@HomeLaptop", then paste the public key into the big text area. Whatever you do, DO NOT, alter the contents of that box at all. If you malform your public key, it won't work. Save the public key and we're sorted.

Now we can test our SSH Key by doing the following:

ashley@laptop:~$ ssh -T git@github.com

It will ask you to set up the RSA fingerprint between your machine and githubs servers.

The authenticity of host 'github.com (207.97.227.239)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? 

If the connection was successful, you'll get a response with the following:

Hi ls12styler! You've successfully authenticated, but GitHub does not provide shell access.

If you see the message above with your username instead of mine, then it means we've got the green light and we're almost ready to rock. We've just got to set a couple of global config options. So in your terminal do the following:

ashley@laptop:~$ git config --global user.name "Ashley Broadley"
ashley@laptop:~$ git config --global user.email "me@example.com"

Once you've done that, we're all done. Next time we'll be going through the basics of using git.

Tags: #git, #dvcs, #github, Comments: Be the first!


Comments closed

Comments:

No Comments Yet!