Setup A Hosted Git Repository With Gitolite
Git has gotten a lot of hype recently, especially among smaller development teams and contractors, for its flexible, distributed environment, ease of use and while Subversion is the old kid on the block, there are pros and cons for each. This article assumes that you already know the intrinsics of the different version control systems and you’ve decided that Git is for you.
Gitolite is a package that allows us to host our repositories using one dedicated user that has restricted access to the host OS and provides access to the source code.
The following steps helped me successfully install and setup Git on a Ubuntu Server 11.04, install gitolite to host my Git repositories and allow secure access over SSH. I’ve not tested other Linux versions, but assume it should be very similar.
The basic steps to setup Git with Gitolite
- Create User
- Generate SSH keys
- Install Git
- Install Gitolite
- Administer Gitolite
Create a Git user on the server
# sudo adduser gituser (enter password when prompted)
Generate SSH RSA keys
On the workstation where you develop and will need access the Git repository, generate a key pair that will be used for authentication. Once generated, we’ll add the public key to the server’s authorized key list file. Ensure that the directory .ssh exists.
# ssh-keygen -t rsa (do not use sudo, specify name as gituser) # scp .ssh/gituser.pub gituser@hostname:.ssh/
You should now be able to login to the server using the certificate and not have to supply a password. Let’s login and proceed with the Git installation.
# ssh gituser@hostname # su # apt-get install gettext # wget http://ftp.de.debian.org/debian/pool/main/g/git/git_184.108.40.206.orig.tar.gz # tar xzvf git_220.127.116.11.orig.tar.gz # cd git-18.104.22.168/ # ./configure # make # make install
Now that we have Git installed, we can use it to get the latest source code of Gitolite. During the checkout, the console output should resemble closely to what’s displayed below.
# su - gituser # git clone git://github.com/sitaramc/gitolite gitolite-source Cloning into gitolite-source... remote: Counting objects: 5425, done. remote: Compressing objects: 100% (2180/2180), done. remote: Total 5425 (delta 3812), reused 4762 (delta 3192) Receiving objects: 100% (5425/5425), 2.01 MiB | 947 KiB/s, done. Resolving deltas: 100% (3812/3812), done.
Next we run the Gitolite install script. It’ll among other things create two new folders as you can see in the output.
The Gitolite install script relies on the path to gl-setup, so we need to add it. The easiest way is to add this line to the .bashrc file in your home directory.
With the path set, we can now finish the installation.
# gl-setup ~/.ssh/gituser.pub
If everything went as planned, you should see a similar output as below.
The default settings in the rc file (/home/gituser/.gitolite.rc) are fine for most people but if you wish to make any changes, you can do so now. hit enter... creating gitolite-admin... Initialized empty Git repository in /home/gituser/repositories/gitolite-admin.git/ creating testing... Initialized empty Git repository in /home/gituser/repositories/testing.git/ [master (root-commit) 4c9dbe8] start 2 files changed, 6 insertions(+), 0 deletions(-) create mode 100644 conf/gitolite.conf create mode 100644 keydir/gituser.pub
Finally remove the public key file.
# rm -f gituser.pub
Gitolite is administered by getting a clone of it’s configuration file from the client, modify it and pushing it to the server. This is how we add users, set permissions and create repositories.
# git clone gituser@hostname:gitolite-admin