Setting up gitolite on Ubuntu 12.04 LTS
In this post we will be looking at how to self-host git using gitolite.
First off, you will have to decide if you are ok with using the (slightly older) version in the Ubuntu package repository.
Right now, gitolite is at version 3, while the version in the LTS repository is 2.
Moving on, in this guide we will be using the repository version.
Use apt-get to install gitolite
sudo apt-get install gitolite
After that’s done, we proceed with configuring gitolite:
sudo dpkg-reconfigure gitolite
You will be presented with some pretty dialog… dialogs with the following questions:
System username for gitolite
You can leave the default gitolite username, but if you want to type less when cloning git repositories, you can set it to git (don’t forget to check if the username not already taken by something else on the system)
If you are unsure, you can leave the default.
Personally, I prefer /home/gitolite
Administrator’s SSH key
You can either upload your public key file (you do have one, right? if not, see here) somewhere on the server and input the path to the file, or paste it directly.
The administrative repository
Gitolite operates under the principle that you have an administrative repository, and you configure everything from there.
Therefore, we clone the administrative repository:
git clone GITOLITE_USERNAME@SERVER_ADDRESS:gitolite-admin.git
git clone firstname.lastname@example.org:gitolite-admin.git
This URI scheme assumes you are using the standard SSH port (22).
If that is not the case, you will have to use the following, lengthier syntax:
git clone ssh://GITOLITE_USERNAME@SERVER_ADDRESS:SERVER_PORT/gitolite-admin.git
git clone ssh://email@example.com:12345/gitolite-admin.git
By default, the gitolite administrative repository looks like this:
gitolite-admin/ |-- conf <-- configuration dir | `-- gitolite.conf <-- configuration file `-- keydir <-- key store directory `-- admin.pub <-- key file, must end in .pub
Creating a new repository
We edit the gitolite-admin/conf/gitolite.conf file and add the following:
repo REPOSITORY_NAME RW+ = USER_KEY_NAME
repo testing RW+ = admin
The permission types are:
- R means “read” permission
- RW means “read and write”, but no rewind
- RW+ means “read and write”, with rewind allowed
Save the config file then commit the changes:
git add . git commit -m "created testing repository" git push
Git documentation is outside the scope of the tutorial.
Congratulations! You now have a new repository which you can clone like so:
git clone firstname.lastname@example.org:testing.git
And that’s it!
But what if we want to give someone else access to our repository?
Adding a new user
First, you need to add his or hers ssh public key to the keydir folder in a file with the following name: user.pub
After that, we edit the gitolite.conf file and add the user to the appropriate directory.
From the gitolite-admin folder, we save and push everything:
git add -A . git commit -m "added user XXX" git push
And that should be it.
- A user can have multiple key files, just add more files and keep this naming pattern: email@example.com, firstname.lastname@example.org, email@example.com. And in the config file you can just reference ‘user’ and it will work with any of the previous three keys.
- Use an openssh ssh_config file to simplify git URIs or ssh connections