This article is part one of a two part series that covers setting up a hosting server using gitosis for your central repository, and in the next article, taking an existing SVN repository and running the appropriate scripts and commands necessary to migrate it into something git can work with.
So this article is how to setup and manage a git repository.There are some great services out there than can do this for you, but why pay money for something you can easily do for free? This article shows how to setup and manage a secure and private git repository that people can use as a central sharing point.
Setting Up Gitosis
Gitosis is a tool for hosting git repositories. Its common usage is for a central repository that other developers can push changes to for sharing.
First clone the gitosis repository and run the basic python install. You just need the python setuptools package
sudo apt-get install python-setuptools
And then you can easily install it
git clone git://eagain.net/gitosis.git cd gitosis sudo python setup.py install
Next you need to create a user that will own the repositories you want to manage. You can put its home directory wherever you want, but in this example we’ll put it in the standard /home location.
sudo adduser \ --system \ --shell /bin/sh \ --gecos 'git version control' \ --group \ --disabled-password \ --home /home/git \ git
Then you must create an ssh public key (or use your existing one) for your first repository user. We’ll use an init command to copy it to server and load it. If you don’t have a public key you can create one with ssh-keygen like so
ssh-keygen -t dsa
Then gitosis-init is for the first time only, loads up your users key, and goes like this
sudo -H -u git gitosis-init < ~/.ssh/id_dsa.pub
Here it doesn't hurt to make sure your post-update hook has execute permissions.
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
Now you can clone the gitosis-admin repository, which is used to manage our repository permissions.
git clone git@YOUR_SERVER_HOSTNAME:gitosis-admin.git cd gitosis-admin
Now you can see you have a gitosis.conf file and a keydir directory
$ ls -l total 8 -rw-r--r-- 1 jgoulah mygroup 83 2009-10-31 20:44 gitosis.conf drwxr-xr-x 2 jgoulah mygroup 4096 2009-10-31 20:44 keydir
The gitosis.conf file holds group and permission information for your repositories, and the keydir folder holds your public keys.
If I look in there I see my public key was imported from our earlier gitosis-init command
$ ls -l keydir/ total 4 -rw-r--r-- 1 jgoulah mygroup 603 2009-10-31 20:44 jgoulah.pub
So open up gitosis.conf and you should already see you have an entry for the gitosis-admin repository that we just cloned. The gitosis-init command above setup the access for us. From now on we can just crack open gitosis.conf and edit the permissions, commit and push back to our central repository.
If I wanted to create a new project for a repository called pizza_maker it would look something like this.
[group myteam] members = jgoulah writable = pizza_maker
Don't forget the members section is the name of your public key file without the .pub at the end. If your key was named XYZ.pub then your member line would have XYC here.
git commit -a -m "Create new repo permissions for pizza_maker project" git push
As a reminder the second part of this series will show an svn to git import. For now lets assume we are starting from scratch. We'd create our project like this
cd && mkdir pizza_maker cd pizza_maker git init git remote add origin git@YOUR_SERVER_HOSTNAME:pizza_maker.git git add * git commit -m "some stuff" git push origin master:refs/heads/master
The only other thing to know is if you want to grant another user access to your repository. All you have to do is add their public key to the keydir folder, and then give the user permissions by modifying gitosis.conf
cd gitosis-admin cp ~/otherdude.pub keydir/
[group myteam] - members = jgoulah + members = jgoulah otherdude writable = pizza_maker
If you need to, you can also grant public access over the git:// protocol like so
sudo -u git git-daemon --base-path=/home/git/repositories/ --export-all
Then someone can clone like
git clone git://YOUR_SERVER_HOSTNAME/pizza_maker.git
This article showed how to setup gitosis, how to initialize your gitosis-admin repository, which is a unique concept in itself to use a repository to manage repositories, and it works rather well. We also went over how to create our own new git repository, and how to manage the access permissions through gitosis.conf. Part two of this series will explain how to port from your current SVN setup to a Git setup. This article was a prerequisite if you want to host your own private repository when you're converting from SVN to Git, and thats what we'll look at next time.