How To Use Gitolite To Setup Git Repositories on Debian

September 4, 2019

Table of Contents

    This tutorial will show you how to easily and conveniently setup git repositories with Gitolite on Debian Wheezy. For the course of this tutorial, we will assume that you are working with administrative privileges. If you want to use sudo instead, append it where necessary.

    First, login via SSH and make sure that your packages are up to date and that the dependencies are met:

    apt-get update && apt-get upgrade && apt-get install git perl
    

    Gitolite depends on a dedicated user for everything git-related, since it acts as a wrapper around it. You can name it whatever you want. We’ll go with git here:

    useradd -m git
    passwd git
    

    Make sure that your own SSH public key has been copied on the server by issuing the following command from your client machine:

    scp yourkey.pub git@yourserver.tld:˜/yourname.pub
    

    https://www.itweb.services/tutorials/linux-guides/how-do-i-generate-ssh-keys”>IT Web Services doc on how to generate them.

    The next step is important. Ensure that your ˜/.ssh/authorized_keys file is empty.

    Download and install Gitolite directly from Github since the version in Debian’s repository is outdated:

    su git
    cd
    git clone git://github.com/sitaramc/gitolite
    mkdir -p $HOME/bin
    gitolite/install -to $HOME/bin
    

    Make yourself an administrative user:

    bin/gitolite setup -pk yourname.pub
    

    The installation is complete. Next, you need to add users and repositories. Contrary to “normal” systems management, Gitolite relies on a special repository for user and repository management, it’s called gitolite-admin.

    Clone gitolite-admin on your client:

    git clone git@yourserver.tld:gitolite-admin
    

    If you cd into gitolite-admin, you should now see two directories:

    • conf
    • keydir

    The directory keydir stores the public keys of users, therefore if you wanted to add a user called user1, you would place their public key in the keydir and name it user1.pub.

    Adding new repositories is done in the file conf/gitolite.conf. To give user1 read and write access to the repository Testing (which is already there by default) you would have to change it to the following:

    repo testing
      5     RW+     =   user1
    

    To make those changes take effect, you have to push the changes to the repository:

    git add conf
    git add keydir
    git commit -m "user1 - testing"
    git push
    

    That’s about everything – repeat the process for every new user / repository. Happy coding!

    Need help?

    Do you need help setting up this on your own service?
    Please contact us and we’ll provide you the best possible quote!