Git Repository Server using Gitolite

Some time ago, I covered setting up a git repository server using gitosis. Since then, gitolite has entered the arena and has built on gitosis adding features such as branch level access control, gitweb control and improved configuration. This guide covers installing gitolite using the non-root method and simple administration.

The documentation for gitolite is pretty comprehensive and I encourage you to read the official install and admin instructions. In addition to the official instructions, I also setup and authorise the git user as this allows any server sync repositories to use the git user as a system account and be able to interact with git repositories hosted in gitolite. This is useful for fetch repositories for svn mirrors for example (the topic of a future post).

The following conventions are used and should be substituted with appropriate values for your environment:

  • username is the username of the person installing gitolite (i.e. you) and is assumed to have an account on the server
  • hostname is the hostname of the git server - add host entries as appropriate (e.g. 172.18.25.102 hostname)
  • git is the username of the user on the git server that will run gitolite and will be created
  • reponame is the name of a repository you want to host

This post assumes that you have a server following the Ubuntu Lucid VPS Base Build post.

Git Packages

The git-core package contains all the basic command line for git. As the server is running headless, there is no point in installing packages such as gitk.

sudo apt-get install git-core

ssh keys

If you already have ssh keys then use those, otherwise create some, e.g.:

cd ~
ssh-keygen -v -t rsa -C username@hostname

Gitolite

Installation

Copy your public key to the server:

scp ~/.ssh/id_rsa.pub username@hostname:username.pub

SSH to the server:

ssh username@hostname

Create the git user that gitolite will run as (i.e. git):

sudo adduser git

Copy the public key over to the git user:

sudo chown git:git username.pub
sudo mv username.pub ~git/username.pub

Log in as the git user:

su - git

Generate ssh keys for git user with no password and copy the public key to your clipboard for later:

ssh-keygen -v -t rsa
cat ~/.ssh/id_rsa.pub

Install gitolite:

cd ~
git clone git://github.com/sitaramc/gitolite gitolite-source
cd gitolite-source
mkdir -p ~/bin ~/share/gitolite/conf ~/share/gitolite/hooks
src/gl-system-install ~/bin ~/share/gitolite/conf ~/share/gitolite/hooks
cd ..
gl-setup username.pub
rm -f username.pub

Administration

You can administer the configuration through git itself on the gitolite-admin repository by cloning, modifying and push changes back to the server.

On your client machine, clone the admin repo:

git clone git@hostname:gitolite-admin

Modify the conf/gitolite.conf file to contain:

@admins     = username git

repo        gitolite-admin
            RW+     =   @admins

repo        testing
            RW+     =   @all

And ensure that the keydir directory contains the following files:

git.pub
username.pub

Add and commit the changes:

git add -A
git ci -m "updated configuration"
git push

Adding repositories

As above, clone the admin repo and append the following to conf/gitolite.conf:

repo        reponame
            RW+     =   username

Add and commit the changes:

git add -A
git ci -m "updated configuration"
git push

You can now add create the project (or skip this for an existing project):

mkdir myproject
cd mypyroject
git init
# do some work, git add and commit files

Then add your server as a remote and push:

git remote add hostname git@hostname:reponame.git
git push hostname master

You can track the remote by adding suitable config:

git config branch.master.remote hostname
git config branch.master.merge refs/heads/master

Comments

blog comments powered by Disqus
Fork me on GitHub