Hosting a git server

Between my work for Profound and my personal projects, the list of git repositories I have to manage has grown quite large over time. Because of this, I chose to host my own git server. It was by far the cheapest option, but also the one that didn’t have me relying on a 3rd party to host my company’s source code. Surprisingly though, it was also the option that turned out the most convenient to manage.

In this post I will walk you through how to setup your own “gitolite” server and start hosting your own git repositories. To get started, make sure you have git installed on your server:

root@server:~$ apt-get install git

Then create a user, that will run gitolite later.

root@server:~$ sudo adduser \
   --system \
   --shell /bin/bash \
   --gecos 'git version control' \
   --group \
   --disabled-password \
   --home /home/gitolite gitolite

In order to provide easy access to gitolite on the remote machine, we need to create a key-pair. This will give your local machine access to the gitolite-admin repository, which is used for your git server’s configuration.

local$ ssh-keygen -t rsa -f ~/.ssh/gitadmin
local$ cat ~/.ssh/ | ssh -p port root@server 'cat >> ~/'
root@server$ mv ~/ /home/gitolite/
root@server$ chown gitolite:gitolite /home/gitolite/

As the newly created user, install gitolite.

root@server:~$ su gitolite
gitolite@server:~$ git clone git://
gitolite@server:~$ mkdir bin
gitolite@server:~$ gitolite/install -to /home/gitolite/bin
gitolite@server:~$ bin/gitolite setup -pk

That’s it, we’re up and running. Right now the only workstation with access, is the one that the came from. In order to add users and new repositories, we’ll have to checkout the gitolite-admin repository.

local:~$ vim ~/.ssh/config

> Host gitbox
>   User gitolite
>   Hostname serverip
>   Port serverport
>   IdentityFile ~/.ssh/gitadmin

local:/folderforrepositories/$ git clone gitbox:gitolite-admin

Adding keys for user authentication:
The folder “keydir” is where user’s keys are stored. Currently, you will see a file in there. That is the “gitolite” user we use to administrate our gitolite installation. You can create a new user called “jens” by copying that person’s public key into the “keydir” directory, naming the key “” and then committing it to the repo.

Adding Users, Usergroups and new Repos:
To manage your git server, simply edit the file gitolite-admin/conf/gitolite.conf in the repository on your local machine. Any changes made in there that are committed back to your gitolite server are automatically applied.

@admin      = jens 
@staff      = jens maria

  repo gitolite-admin
    RW+     = gitadmin @admin

  repo testing
    RW+     = @all

  repo someotherrepo
    RW+     = jens @admin
    R       = @staff

I hope that gives you a good overview of how to host your own git server. If you found this helpful, please subscribe to this blog or follow my company at @weareprofound.

Useful Terminal Commands

A collection of random, but useful Shell commands.