How to install a GIT repository

From Cosmin's Wiki

Jump to: navigation, search

Home > Linux how to's > How to install a GIT repository



I have been using CVS as a version control system for many years, and being used to it I was quite convinced that it's the perfect VCS. Then I have come across GIT. The first day was tough, as everything was new and I would always compare it with CVS and all I could find was minuses. Then, step-by-step, I started loving GIT.

Actually, among the things I love most about it are:

  • that it creates a local copy of the whole repository, being able to commit / branch / undo work
  • that every commit takes a snapshot of the whole project, thus getting rid of the boring tag-ing I had to do in cvs
  • the ease of using (creating, merging) branches
  • many more ... but let's keep just a "top" list

Well, now back to the very purpose of this post. Using git locally is very easy. But, due to safety measures (and for being able to work in a distributed environment with several programmers), I had to create a "public" repository everybody could access. This was a not-so-easy to do task (at least in the beginning) - now I find it quite simple. Thus, as always, in order not to forget how I did it, here is the cookbook of installing a public git repository with gitolite - to ensure key-based authentication over ssh.

At the moment of writing this post I am using Debian 5 (lenny) on my servers, so the procedure below addresses this distribution version. First, edit the /etc/apt/sources.list file and add

deb http://backports.debian.org/debian-backports lenny-backports main contrib non-free

to it, and then of course

#> aptitude update

Now install the git-core package as follows

#> aptitude install -t lenny-backports git-core

Then you can comment out the line added in sources.list and do again an an "aptitude update"

Now, create a local user on the server which will host the repository

#> adduser gitolite

Create now a pair of private/public keys (use ssh-keygen -t rsa) and copy the public key onto the gitolite home directory as gitolite.pub

Get now the latest version of gitolite from their git repository (being logged as the gitolite user on the server):

~$ cd ~
~$ git clone git://github.com/sitaramc/gitolite gitolite-source
~$ cd gitolite-source/
~/gitolite-source $ mkdir -p ~/bin ~/share/gitolite/conf ~/share/gitolite/hooks
~/gitolite-source $ src/gl-system-install ~/bin ~/share/gitolite/conf ~/share/gitolite/hooks

A message like the following appears:

 ***** WARNING *****
gl-setup is not in your $PATH.
 
Since gl-setup MUST be run from the PATH (and not as src/gl-setup or such),
you must fix this before running gl-setup.  The simplest way is to add
 
    PATH=/home/gitolite/bin:$PATH
 
to the end of your bashrc or similar file.  You can even simply run that
command manually each time you log in and want to run a gitolite command.
 
Run src/gl-system-install -h for a detailed usage message.

so it might be wise to add that line to your .bashrc file. I did! After adding the line do not forget to run

source .bashrc
to update.

Now:

~/gitolite-source $ cd ~
~$ gl-setup gitolite.pub
 

This will give you the chance to tweak some of the settings in the .gitolite.rc file. However, for most cases you won't need to change anything, so just :x from vim and let the script finish it's job. If everything went fine, you will end up with 2 repositories: gitolite-admin and testing. Now you can safely remove the public key you had in the home folder of the gitolite user:

~$ rm -f gitolite.pub

And we are done with the installation part. Now on to the configuration.

For the next part I will assume that your server is ssh-accessible with public keys over a custom port (say 1234). Now go to your client machine and clone the gitolite-admin repository as such:

~$ git clone ssh://gitolite@yourserver.com:1234/gitolite-admin

-- Adding a user -- To add a user to a git repository all you have to do is copy a file <username>.pub (cosmin.pub in my case) to the keydir directory.

-- Creating a new repository -- For creating / managing repositories, you would edit the gitolite.conf file under the conf directory:

repo    gitolite-admin
        RW+     =   gitolite
 
repo    my-project
        RW+     =   cosmin

Then just :

~$ git add -A
~$ git commit -a -m "added new repo"
~$ git push origin master

and ... you're done !


-- ATTENTION -- Pay great attention as which user you log into the git repository and which key you'll use for this: user gitolite -> use it only for the git administration other users ... use it for working on your repositories