Git Repository Server using Gitosis

This post assumes that you have a server following the Ubuntu Jaunty Base Server Build.

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


Gitosis is a useful tool for managing git repositories using ssh. Gitosis can be obtained using git:

mkdir ~/src
cd ~/src
git clone git://

README.rst contains instructions for setting up and managing gitosis.


The following outlines the steps I took.

Ensure you have python-setuptools:

sudo apt-get install python-setuptools

Install gitosis:

cd gitosis
sudo python install

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

sudo adduser \
    --system \
    --shell /bin/bash \
    --gecos 'git version control' \
    --group \
    --disabled-password \
    --home /home/git \

Initialise gitosis with your ssh key so you can administer the configuration (assuming you have already setup ssh via certification):

sudo -H -u git gitosis-init < /home/username/.ssh/authorized_keys

Also make sure the post-update hook script is executable:

sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update


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

Clone the gitosis-admin repository:

git clone git@hostname:gitosis-admin.git

Modify gitosis.conf adding a group for the new repository:

[group groupname]
writable = reponame
members = username

Note that you can reuse a group for other repositories should you want to. Generally I use the same groupname as the reponame. members and writable are comma separated lists.

Add, commit and push your changes to the repository:

git add -A
git ci -m "added reponame"
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 serveralias git@hostname:reponame.git
git push serveralias master

You can track the remote by adding suitable config:

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


blog comments powered by Disqus
Fork me on GitHub