Čia yra sena dokumento versija!
gitosis is a tool for hosting git repositories (I'm repeating myself for those who skim :) The first thing to do is grab a copy of gitosis and install it on your server:
cd ~/src
git clone git:eagain.net/gitosis.git
Notice that gitosis is extremely light-weight. The clone takes a mere couple seconds. Less is more, and I like that a lot.
Next, install it like so:
cd gitosis
python setup.py install
Don't use –prefix unless you like self-inflicted pain. It is possible to install gitosis in a non-standard location, but it's not nice. Read the Caveats section at the bottom and then come back here.
If you get this error:
-bash: python: command not found
or
Traceback (most recent call last):
File „setup.py“, line 2, in ?
from setuptools import setup, find_packages
ImportError: No module named setuptools
You have to install Python setuptools. On Debian/Ubuntu systems, it's just:
sudo apt-get install python-setuptools
For other systems, someone tell me or leave a comment, so I can update this section and improve this tutorial.
The next thing to do is to create a user that will own the repositories you want to manage. This user is usually called git, but any name will work, and you can have more than one per system if you really want to. The user does not need a password, but does need a valid shell (otherwise, SSH will refuse to work).
sudo adduser \
–system \
–shell /bin/sh \
–gecos 'git version control' \
–group \
–disabled-password \
–home /home/git \
git
You may change the home path to suit your taste. A successful user creation will look similar to:
Adding system user `git'…
Adding new group `git' (211).
Adding new user `git' (211) with group `git'.
Creating home directory `/home/git'.
You will need a public SSH key to continue. If you don't have one, you may generate one on your local computer:
ssh-keygen -t rsa
The public key will be in $HOME/.ssh/id_rsa.pub. Copy this file to your server (the one running gitosis).
Next we will run a command that will sprinkle some magic into the home directory of the git user and put your public SSH key into the list of authorized keys.
sudo -H -u git gitosis-init < /tmp/id_rsa.pub
id_rsa.pub above is your public SSH key that you copied to the server. I recommend you put it in /tmp so the git user won't have permission problems when trying to read it. Success looks like:
Initialized empty Git repository in ./
Initialized empty Git repository in ./
(Yes, two times)
For good measure, let's make sure the post-update hook is set executable. I've seen it where sometimes it doesn't get set (problem with older setuptools):
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update
Here some cool magic happens. Run this on your local machine:
git clone git@YOUR_SERVER_HOSTNAME:gitosis-admin.git
cd gitosis-admin
You will now have a gitosis.conf file and keydir/ directory:
~/dev/gitosis-admin (master) $ ls -l
total 8
-rw-r–r– 1 garry garry 104 Nov 13 05:43 gitosis.conf
drwxr-xr-x 3 garry garry 102 Nov 13 05:43 keydir/
This repository that you just cloned contains all the files (right now, only 2) needed to create repositories for your projects, add new users, and defined access rights. Edit the settings as you wish, commit, and push. Once pushed, gitosis will immediately make your changes take effect on the server. So we're using Git to host the configuration file and keys that in turn define how our Git hosting behaves. That's just plain cool.
From this point on, you don't need to be on your server. All configuration takes place locally and you push the changes to your server when you're ready for them to take effect.
Creating new repositories
This is where the fun starts. Let's create a new repository to hold our project codenamed FreeMonkey.
Open up gitosis.conf and notice the default configuration:
[gitosis]
[group gitosis-admin]
writable = gitosis-admin
members = jdoe
Your „members“ line will hold your key filename (without the .pub extension) that is in keydir/. In my example, it is „jdoe“, but for you it'll probably be a combination of your username and hostname.
To create a new repo, we just authorize writing to it and push. To do so, add this to gitosis.conf:
[group myteam]
members = jdoe
writable = free_monkey
This defines a new group called „myteam“, which is an arbitrary string. „jdoe“ is a member of myteam and will have write access to the „free_monkey“ repo.
Save this addition to gitosis.conf, commit and push it:
git commit -a -m „Allow jdoe write access to free_monkey“
git push
Now the user „jdoe“ has access to write to the repo named „free_monkey“, but we still haven't created a repo yet. What we will do is create a new repo locally, and then push it:
mkdir free_monkey
cd free_monkey
git init
git remote add origin git@YOUR_SERVER_HOSTNAME:free_monkey.git
# do some work, git add and commit files
git push origin master:refs/heads/master
With the final push, you're off to the races. The repository „free_monkey“ has been created on the server (in /home/git/repositories) and you're ready to start using it like any ol' git repo.
Adding users
The next natural thing to do is to grant some lucky few commit access to the FreeMonkey project. This is a simple two step process.
First, gather their public SSH keys, which I'll call „alice.pub“ and „bob.pub“, and drop them into keydir/ of your local gitosis-admin repository. Second, edit gitosis.conf and add them to the „members“ list.
cd gitosis-admin
cp ~/alice.pub keydir/
cp ~/bob.pub keydir/
git add keydir/alice.pub keydir/bob.pub
Note that the key filename must have a „.pub“ extension.
gitosis.conf changes:
[group myteam]
- members = jdoe
+ members = jdoe alice bob
writable = free_monkey
Commit and push:
git commit -a -m „Granted Alice and Bob commit rights to FreeMonkey“
git push
That's it. Alice and Bob can now clone the free_monkey repository like so:
git clone git@YOUR_SERVER_HOSTNAME:free_monkey.git''
Alice and Bob will also have commit rights.