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.
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:
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.
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:
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:
chmod 666 /tmp/gituser.pub su gitolite gl-setup /tmp/gituser.pub
Now you have added a user to the git server.
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:
git config --global user.name "firstname lastname" git config --global user.email firstname.lastname@example.org
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.
git clone gitolite@server:gitolite-admin cd gitolite-admin/ vi conf/gitolite.conf
This file should already contain a couple of repositories:
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:
repo mytest RW+ = gituser
Save that file, and we can then commit it back to the server:
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:
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:
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!
These 2 sites are a great resource to understanding git and how to do different tasks.
I’d also recommend you get a hold of the Pro Git book:
Well, happy coding now!