Sunday, June 26, 2011

How To Install Gitolite

Gitolite is a tool to easily manage repositories in git with just a user account on a server. It provides access to several developers, without providing real access to a shell. It uses the ssh key. It is written by Sitaram Chamarty in the Perl language, and inspired gitosis. Gitolite can assign specific rights to a user, such as reading, (So the clone and fetch) write (push) for a repo. It is also possible to assign rights to branches or tags, practiced in a corporate environment or in the management of certain projects, for example. Gitolite can be installed without root privileges, and without additional software, only Git and Perl.

For installation, there are several ways to proceed. For users of Debian, Ubuntu, Fedora, and certainly others, it is possible to use the package system of distribution. It is also possible to start the installation with a script provided by the project. It is the solution that I use so it's the one I'll present. As I said above, Gitolite can be installed without using root privileges. So I prefer to create an individual user to manage the installation, it is also the user who will manage Git repositories. Not using the root account you can be sure access to the configuration of Git repositories has no root rights. We can then add user's public keys in / home / git / .ssh / authorized_keys.

adduser gitadmin
adduser git

Then we will take the identity of the newly created user gitadmin, and we will generate a key pair, which will add to the list of keys authorized git.

sudo su gitadmin
ssh-keygen -t dsa -b 1024
ssh-copy-id -i ~/.ssh/id_dsa.pub git@localhost

It is now possible to proceed to the installation. From the home folder of gitadmin - we start by recovering the sources of project, by cloning the project. We move into the project and we start the installation script. Note: we need to have at least Git 1.6.2 version or higher for Gitolite to work.

git clone http://github.com/sitaramc/gitolite.git
gitolite cd / src
. /gl-easy-install git localhost gitadmin

The options we pass a parameter to the install script, meaning the user will host git repositories, the server you are connected over here then localhost and the user gitadmin for the administration of repos. A series of questions will be asked, you can leave the default options. It will also be asked for a passphrase that can be left empty. Once installation is complete, we can begin to see how the configuration. It moves in the directory gitolite-admin, always with the user gitadmin of course. (User who manages the configuration) To add a user, add the public key in the folder Keydir, commit and do not forget to push as it is when the hooks that the configuration takes effect.

cp /home/lexter/id_dsa.pub Keydir/lexter.pub
git add Keydir/lexter.pub
git commit -a -m "Added user Lexter."
git push

If like me, there are more keys for the same user, there is a special syntax to use. lexter@lexter.pub lexter@work.pub - the name after the at sign may be what you want.
To delete a user, delete their key:

git rm Keydir/usersample.pub
git commit -a -m "Deleted usersample."
git push

Now to the management of repositories. Currently, two existing repo. There are of course the gitolite-admin repository and a repository-admin called testing. We note that the syntax and fairly clear and easy to understand. If we add the name of a repo that does not exist, it will be created automatically and placed in the directory / home / git / repository.

repo lexterproj
RW+ = lexter

It has such a repo, with the user who has rights lexter read, write, rewind permissions, in other words the ability to delete milestones. R: Right read only, RW: Right reading and writing, RW+: right reading, writing and rewind permission. It is also possible to manage groups. There is already a group that is @ all , it is used for testing the repo, this corresponds to all users.

@New_group = User1 user2 user3

It is now possible to use @ New_group. It is also possible to add only those rights on a branch of a repo. If you need more information about this you can see a sample configuration https://github.com/sitaramc/gitolite/blob/master/conf/example.conf. To get the project that uses git.

git clone git@host.com: lexterproj.git

One simple way to add/move a pre-existing repo to gitolite is to let gitolite create it as a brand new repo, then do the following:

cd [copy-of-your-repo]
# make sure all the branches are correct and no extra stuff, "temp"
# branches, etc., are present
git push --all git@server:reponame.git
git push --tags git@server:reponame.git

Please do a git ls-remote git@server:repo to make sure all the stuff you want went through, and is named correctly.

In conclusion, I find it really a handy tool, nice and powerful. It is very easy to configure and maintain.