How to configure a git server on Ubuntu 10.10

A friend of mine asked me for some help installing git sever on ubuntu. I wanted to do this myself at home, so I took the opportunity to do it and use that as a document for him. There are a number of good sources online with regard to this type of installation but I found that I needed to piece it together from several of them to get a working system. I chose gitolite for the multiuser component as it seems to be the one most folks recommend.

Server install
To begin with, we had n ubuntu 10.10 system installed and online. You will need to get the necessary git server software installed to begin. This can be done using apt-get:

server

sudo apt-get install git-core
sudo apt-get install gitolite
sudo apt-get install git-daemon-run

At this point your server software is installed, and will start up following a reboot.

Add a user

On the client computer you will need to set up ssh key authentication. To generate an ssh key, follow the example below, entering your own password that you want to use to access your git repository.

client

ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/gituser/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/gituser/.ssh/id_rsa.
Your public key has been saved in /home/gituser/.ssh/id_rsa.pub.
The key fingerprint is:
61:bf:f5:2d:f6:ed:cd:10:b7:0c:be:5d:4d:8f:a3:0d gituser@client

Once this key is generated you will need to transfer the public version of the key to your git server. You can do this using scp:

client

scp /home/gituser/.ssh/id_rsa.pub user@gitserver:/tmp/gituser.pub

Now you need to go back to the gitserver and add this key to git:

server

chmod 666 /tmp/gituser.pub
su gitolite
gl-setup /tmp/gituser.pub

Now you have added a user to the git server.

Client configuration

There is very little to do to allow your client to connect to the git server now, and really I only set up the following for myself:

client

git config --global user.name "firstname lastname"
git config --global user.email email@email.com

Adding a repository to your new git server

Finally, lets set up a test repository. To do this we need to first check out the gitolite-admin repository from the git server and edit the configuration file and then check it back in.

client

git clone gitolite@server:gitolite-admin
cd gitolite-admin/
vi conf/gitolite.conf

This file should already contain a couple of repositories:

client

        repo    gitolite-admin
                RW+     =   gituser
 
        repo    testing
                RW+     =   @all

You can create a new repository by adding a couple of lines to the bottom of that file:

client

       repo    mytest
                RW+ = gituser

Save that file, and we can then commit it back to the server:

client

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

You should see output like the following, this creates the repository on the git server:

client

Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 398 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
Already on 'master'
creating mytest...
Initialized empty Git repository in /var/lib/gitolite/repositories/mytest.git/
To gitolite@gitserver:gitolite-admin
   610d463..98a9226  master -> master

Now that we have a new repository, we can clone it to our local client system and add files to it:

client

cd
git clone gitolite@gitserver:mytest
cd mytest
echo â??This is a testâ? > readme.txt
git add .
git commit -m "Initial checkin of readme.txt"
git push origin master

Now you can delete that entire directory and clone it back from the server again and you will find your readme.txt file again. Very cool!

External links

These 2 sites are a great resource to understanding git and how to do different tasks.

http://www-cs-students.stanford.edu/~blynn/gitmagic/

http://help.github.com/git-cheat-sheets/

I’d also recommend you get a hold of the Pro Git book:

http://progit.org/

Well, happy coding now!

Innovative Engineer/Technologist: Innovatative app developer, systems architect, and project manager in a wide variety of technologies. I am particularly interested in learning about and creating new technology by looking at the 30,000 foot view to see how things can fit together in new and exciting ways. I started my career working at Internet Service Providers and moved into VoIP and Unified Messaging Applications. I currently work in the Switch Networking field. I am constantly looking at new technologies to enhance my own vision of technology as a whole. I consider myself to be of a new generation of Engineers that are able to use and understand technologies while still able to communicate and work with non-technical people.

Tagged with:
Posted in Technology
about.me
coLLin LeGault

coLLin LeGault

Your Personal Technology Consultant

Innovative Engineer/Technologist: Innovatative app developer, systems architect, and project manager in a wide variety of technologies. I am particularly interested in learning about and creating new technology by looking at the 30,000 foot view to see how things can fit together in new and exciting ways. I started my career working at Internet Service Providers and moved into VoIP and Unified Messaging Applications. I currently work in the Switch Networking field. I am constantly looking at new technologies to enhance my own vision of technology as a whole. I consider myself to be of a new generation of Engineers that are able to use and understand technologies while still able to communicate and work with non-technical people. Click the link below to contact me.