August 2, 2011 ahydle

GIT Hosting with gitolite

Setting up GIT hosting using gitolite

This is my first git server and after some reading I decided to build gitolite to manage my git repositories.

To begin building we need to generate a public/private key pair on your workstation and then we need to download and install gitolite from github since gitolite is not currently available in my servers distribution (Ubuntu 10.04). Alternately, you could install gitolite from your distribution (but that may change these instructions a bit).

From your workstation

First I generated a DSA keypair on my workstation.

$ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/Users/jdoe/.ssh/id_dsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/jdoe/.ssh/id_dsa.
Your public key has been saved in /Users/jdoe/.ssh/
The key fingerprint is:
cc:b3:ff:f4:54:22:64:fa:3r:35:45:v4:d4:a3:54:98 jdoe@WKSTN.local
The key's randomart image is:
+--[ DSA 1024]----+
| .o...           |
|E ..o.o          |
| = ... o.        |
|=. .. .o =       |
|+ . ..o X .      |
|.  . . + .       |
|        +        |
|                 |
|                 |

Next transfer the PUBLIC key to the server (ending in .pub)/

$ scp .ssh/

On the server

Copy the public key to a place we can get to with another user later.

$ cp ~/ /tmp

Add a new user to host the git server (all repositories will reside in this home directory).

$ sudo adduser git

Next you will need to make sure that $HOME/bin is in your default path.

$ sudo su - git 
$ echo $PATH

Because $HOME/bin is not in my default path I will add it to my .bashrc

$ vi ~/.bashrc

…add the following line


You will need to exit out of the session and re-enter to make sure that the path was updated. Notice that /home/git/bin has been added

$ sudo su - git
$ echo $PATH

To install gitolite we will check out the files from github using git

$ git clone git://
Initialized empty Git repository in /home/git/gitolite/.git/
remote: Counting objects: 4221, done.
remote: Compressing objects: 100% (1515/1515), done.
remote: Total 4221 (delta 2916), reused 3938 (delta 2657)
Receiving objects: 100% (4221/4221), 1.13 MiB | 990 KiB/s, done.
Resolving deltas: 100% (2916/2916), done.

…and begin setting it up

$ cd gitolite
$ src/gl-system-install
$ ~/bin/gl-setup /tmp/

Back on your workstation

Clone a copy of the server to your computer. It is my preference to store my repositories on an encrypted disk image on my computer. You can use any of the following software to do this. After cd to the directory where you will store your clone and run the command below.

  • Disk Utility in Mac OSX to create encrypted disk images
  • Download and use TrueCrypt
  • Purchase a copy of PGP
$ git clone

Adding Repositories and Users

Now that there is a local copy of the gitolite-admin repository on your computer you can begin adding users or repositories. All the configuration is done in the gitolite-admin folder and once you are done making changes simply commit your changes and push them back up to the server.

To add new repositories edit the conf/gitolite.conf file. If you look at the file you may notice that it is organized by first specifying a repository and then under it the users who have access to the repository are configured along with their permissions. User names are the first part of a public key name (i.e. = jdoe).

Example conf/gitolite.conf

repo    gitolite-admin
        RW+     =   id_dsa

repo    testing
        RW+     =   @all

So lets say I have a new user named Steve Franko who wants a new repository for him and I to share data.

  • I ask Steve Franko to generate a new public/private key pair using ”ssh-keygen -t dsa
  • I ask Steve Franko to send me the PUBLIC key he just generated
  • I rename the public key from to
  • I copy the key into the gitolite-admin/keydir directory

Now that I have a new users key in the keydir directory I will setup my new repository and give him and I permissions:

$ vi conf/gitolite.conf
repo    gitolite-admin
        RW+     =   id_dsa

repo    testing
        RW+     =   @all

repo    new-project
        RW+     =   id_dsa
        RW+     =   sfranko

Commit and Push

$ git commit -a
$ git push

Moving an existing repository into gitolite

In a previous post I migrated some repositories from Subversion that I now need to get into gitolite. In order to do this I am going to create empty repositories and then push the existing repositories up to my new repositories.

To create the new repository I first need to edit the gitolite.conf file and push up my changes.

$ vi conf/gitolite.conf
repo    gitolite-admin
        RW+     =   id_dsa

repo    testing
        RW+     =   @all

repo    myrepo
        RW+     =   id_dsa

Commit and Push

$ git commit -a
$ git push

Next I cd into my existing repository that I had converted earlier and push it up to the server.

$ cd ~/myrepo
$ git push --all
$ git push --tags

To finish I wanted to verify that I did have a fully functioning repository so I deleted my local copy on my computer, cloned a copy from the server, selected a file and reverted it back to a version several years before.

$ rm -rf ./myrepo
$ git clone

Search the log for a file that was updated several years ago.

$ git log --name-only

Copy the current version of the file outside of my repository.

$ cp file ~/Desktop

Restore the previous version I found in the log and compare it to my current version to make sure I can restore a previous version of a file.

$ git checkout 389y5r8qfhhqwfhfujh file
, , , , , , ,

Comment (1)

  1. Pingback: URL

Leave a Reply

Your email address will not be published. Required fields are marked *