Git and Gitosis on Ubuntu 10.10

Introduction and package installation

In this howto we'll not be covering the basic concept and usage of the Git VCS but just the installation procedure on Ubuntu 10.10.
Let's start installing the needed packages:
sudo apt-get install git-core gitosis
This will install all the packages and create the gitosis user.

Public key and initial configuration

To work with gitosis you need to setup a public key of a remote account that connects to the server via ssh to the server gitosis user.
If you don't already have somewhere on the server the public key you need to generate it on your local machine:
ssh-keygen -t dsa
and then copy it to the remote host:
scp ~/.ssh/id_dsa.pub user@remotehost.example.com:
at this point we can initialize gitosis with the key (on the remote server):
sudo -H -u gitosis gitosis-init < id_dsa.pub
You should get an output similar to this one:
Initialized empty Git repository in /srv/gitosis/repositories/gitosis-admin.git/
Reinitialized existing Git repository in /srv/gitosis/repositories/gitosis-admin.git/

Cloning the gitosis-admin and adding a new project

We can now clone the gitosis-admin repository to our local box:
cd ~
git clone gitosis@remotehost.example.com:gitosis-admin.git
You should now have a local clone of the repository on your box, working with the configuration files in gitosis-admin you can add new projects, users, etc.
Inside the gitosis repository you'll find a folder called "keydir" with a copy of your inital imported key: you'll have to place all additional keys for additional users inside the directory with the ".pub" extensions.
We can now edit the configuration file to add users and projects:
nano gitosis.conf
to make it look like this:
[gitosis]
 
#
# users (we made a group because every user could have more public keys for multiple PC)
#
[group user1]
members = user1@box1
 
[group user2]
members = user2@box1 user2@box2
 
#
# repository for gitosis (insert only administrative users)
#
[group gitosis-admin]
writable = gitosis-admin
members = @user1
 
#
# group of users to make up a team
#
[group team-name]
members = @user1 @user2
 
#
# first repository with a team working on it
#
[group projectname]
members = @team-name
writable = folder-name \
               second-folder
When you're satisfied with your configuration just commit and push the changes:
git add .
git commit -a -m "Added initial projects configurations"
git push

Setting up repositories in a folder structure

If you want to setup a lot of repositories and want to subdivide them logically in a folder structure you'll to create those folder manually:
sudo mkdir /srv/gitosis/repositories/project
sudo chown gitosis.gitosis /srv/gitosis/repositories/project
of course the gitosis.conf should refer with the writable parameter to the right path.

First Push

Now that we have set up gitosis with the right keys and permission, let's create the first project by doing a first push from your local box:
# move to the folder containing the project you want to insert on git
cd testproject
 
# this will create the project
git init
 
# add all the files
git add .
 
# do a local commit
git commit -a -m "Initial import"
 
# add the remote repository
git remote add origin gitosis@remotehost.example.com:optional-folder/testproject.git
 
# push everything to the remote server
git push origin master

Visit the website of the company behind these tutorials: www.qaniklab.it