A Shared Git Server

May 10, 2013
Karen

If you work on a team project using git version control, you might want a centralised place from which to push and pull commits from while you collaborate. You can use Github, but if your project is not open source, somebody has to pay for the account. If you want something that is free and you can host yourself, there is Gitorious. However, if you want something lightweight and want to do it yourself, it’s not that difficult. Here’s what I did:

1. Install Git:

sudo apt-get install git-core

2. Create a group:

addgroup gitcommitters

3. Make a place for your repositories to live and allow the group the access it needs:

mkdir /var/git
chown root:gitcommitters /var/git
chmod g+w /var/git

4. Create users:

Add the users to the gitcommitters group

usermod -G gitcommitters karen

Add them a symlink in their home directory – for easier git paths!

ln -s /var/git

Install a public key for each user in their .ssh/authorized_keys2 file.

5. Create repositories:

Each repository you create needs to be a bare repository and you need to give the group access to it.

mkdir /var/git/myprojectname
cd /var/git/myprojectname
git init --bare --shared=group
cd ../
chgrp -R gitcommitters myprojectname
chmod -R g+w myprojectname

Using The Shared Git Server

Each user will need to set SSH to automatically use their private key because there is no option to specify it in the git clone command. This is done by editing their .ssh/config file.

To start a fresh project using an empty repository you just created, do:

git clone ssh://karen@example.com/~/git/myprojectname myprojectname-local

If you already have a local repository that you want to push to the shared server, do:

git remote add --track master origin ssh://karen@example.com/~/git/myprojectname