Install your own git-server

February 23, 2015

Installing gitolite

As always I start with a freshly installed debian installation.

Place you public ssh key somewhere on the server. I put it in the tmp folder. It needs to be named [username].pub.

# FROM YOUR LOCAL MACHINE
$ scp ~/.ssh/id_rsa.pub git.server:/tmp/username.pub

Create a gitolite group and git user

$ addgroup gitolite
$ adduser --disabled-password --home /home/git --ingroup gitolite git

Lets install gitolite

$ apt-get install gitolite

Append www-data to gitolite group so gitweb can access the repos:

$ usermod -a -G gitolite www-data

Setup gitolite

$ su - git
$ gl-setup /tmp/username.pub

Setup will allow you to modify gitolite config umask settings so that new repos are given permissions to enable gitweb.

# change $REPO_UMASK = 0077; to $REPO_UMASK = 0027; # gets you 'rwxr-x---'
$ vim /home/git/.gitolite.rc

$ chmod g+r /home/git/projects.list
$ chmod -R g+rx /home/git/repositories

You should now be able to clone the gitolite-admin.git repository that’s created automatically by the gitolite setup script:

# FROM YOUR LOCAL MACHINE
git clone git@git.server:gitolite-admin.git

Edit conf/gitolite.conf to allow gitweb to the repos.

# FROM YOUR LOCAL MACHINE
$ cd gitolite-admin
$ vim conf/gitolite.conf

# change to:
repo    testing
      RW+     =   @all
      R       =   daemon

$ git add conf/gitolite.conf
$ git commit -m "Allow gitweb to all repos"
$ git push
$ cd ..

For more configuration option check the manual.

Using the repos

Clone a new repo.

$ git clone git@git.server:new_repo.git

Add your existing code to an empty repo.

$ git remote add origin git@git.server:new_repo.git

Installing gitweb

Install gitweb using apt. Notice that you will need apache to use this.

$ apt-get install gitweb

Change the gitweb configuration to use the gitolite repo paths

$ vim /etc/gitweb.conf
# change $projectroot to /home/git/repositories
# change $projects_list to /home/git/projects.lis

Your gitweb should be available at http://git.server/gitweb

You can change this by editing /etc/apache2/conf.d/gitweb. Setup a read-only daemon

Install the git-daemon.

$ apt-get install git-daemon-run

Edit the config file to fit out configuration.

$ /etc/sv/git-daemon/run

#!/bin/sh
exec 2>&1
echo 'git-daemon starting.'
exec chpst -ugitdaemon:gitolite \
  "$(git --exec-path)"/git-daemon --verbose --base-path=/home/git/repositories /home/git/repositories

Restart the daemon.

$ sv restart git-daemon

You can now clone project anonymously.

$ git clone git://server/git_repo.git

Note: Only the repositories the daemon user has Read access to are available.

comments powered by Disqus