Git

At work we recently switched from subversion to Git for our version control. I wont go into it too much, but the main reasons where:

  • We wanted a distributed system, for the flexibility it offers individuals
  • We wanted the enhanced branch/merge
  • Just for fun really, broaden our horizons

Anyway, I love GitHub, but it's not the answer to everything! I wanted a central repository that I could control, so having had a brief glimpse at Gitorious and gitosis, I settled on gitolite. Now, I'm usually quite a lazy sys admin, and unless I desperately need a feature in the latest version of an application, I'm usually happy to fall back on the my chosen package manager, in this case Ubuntu's APT. Gitolite got a package as of version 10.10 Maverick Meerkat, so I told our local Ubuntu mirror to download all the 10.10 packages and after that, upgraded the server I had in mind so that I could use the gitolite package.

Install Gitolite

Nice and easy this part, on the server:

server> sudo apt-get update
server> sudo apt-get install gitolite

Creating a Public/Private key pair

If you already have one, send the public halve over to the server and skip this part. Otherwise, take a look at ssh key based authentication, then create your key pair on your client machine:

client> ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/davem/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/davem/.ssh/id_rsa.
Your public key has been saved in /home/davem/.ssh/id_rsa.pub.
The key fingerprint is:
61:bf:f5:2d:f6:ed:cd:10:b7:0c:be:5d:4d:8f:a3:0d davem@client
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|                 |
|        o        |
|       . o       |
|        S . ... o|
|           o..o*+|
|          . E.Bo=|
|             =o*+|
|            ...o*|
+-----------------+

Once created, send the public halve to the gitolite server. Be sure to use the name you provided when creating the key. In this example, I've called the key davem.pub on the target machine, so I can differentiate between myself and other developers.

client> scp ~/.ssh/id_rsa.pub server:davem.pub

Configure gitolite

On the server, copy the public halve to a convenient location and run the gl-setup tool.

server> mv davem.pub /tmp/davem.pub
server> chmod 666 /tmp/davem.pub
server> sudo su gitolite
server> gl-setup /tmp/davem.pub
...

That's gitolite setup, we now need to go back to the client machine to fully configure it. First edit your .ssh/config file, so that ssh knows how to connect to the server. Again, be careful to use the correct name for your key pair:

Host servername
IdentityFile ~/.ssh/id_rsa

Now we can clone the git repository that is used to configure gitolite:

client> git clone gitolite@server:gitolite-admin
Initialized empty Git repository in /home/davem/gitolite-admin/.git/
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
client> cd gitolite-admin

Adding repositories

The gitolite admin contains two folders. The first, conf contains a single config file. Open that and create a new repository by adding:

        repo    mytest
                  RW+     =   @all

You then need to commit the changes and push them to the gitolite server:

client> git commit -m "Added mytest repo" conf/gitolite.conf
client> git push

We then should be able to clone our new repository:

client> git clone gitolite@server:mytest

Adding users

To add a new user, simply add their public key halve to your clone of the gitolite-admin repo, add, commit and push.

client> cd gitolite-admin
client> cp ~/Downloads/another.pub keydir/
client> git add keydir/another.pub
client> git commit -m "Added another as a user" keydir/another.pub
client> git push

I wont go any further than that, you can configure fine grain access control and other things in the conf/gitolite.conf file, check out the documentation. Hope it's been helpful, comments (especially corrections) are appreciated.