Firstly, grab the source from the git web repository.
$ cd /usr/local/src
$ git clone git://eagain.net/gitosis.git
Initialized empty Git repository in /usr/local/src/gitosis/.git/
remote: Counting objects: 603, done.
remote: Compressing objects: 100% (172/172), done.
remote: Total 603 (delta 425), reused 597 (delta 422) Receiving objects: 100% (603/603), 92.87 KiB | 23 KiB/s, done. Resolving deltas: 100% (425/425), done.
Once downloaded, we can run the installation.
$ cd gitosis
$ python setup.py install
Then we need to create user
sudo adduser \
--system \
--shell /bin/sh \
--gecos 'git version control' \
--group \
--disabled-password \
--home /home/git \
git
$ sudo -s
root $ su -git
$ ssh-keygen -t rsa
Generating public/private rsa key pair. Enter file in which to save the key (/home/git/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/git/.ssh/id_rsa. Your public key has been saved in /home/git/.ssh/id_rsa.pub. The key fingerprint is: 59:a8:a8:0a:f7:b5:0e:eb:74:c4:66:cb:ac:03:84:da git@localhost The key's randomart image is:
+--[ RSA 2048]----+
| |
| . |
| . . . |
|. . o . o |
|.o . * S |
|. E. * . |
|. o.o * |
|.o o.* . |
|. .=oo |
+-----------------+
git$ ls -al .ssh
total 16
drwx------ 2 git git 4096 2009-02-11 14:52 .
drwx------ 5 git git 4096 2009-02-11 14:52 ..
-rw------- 1 git git 1743 2009-02-11 14:52 id_rsa
-rw-r--r-- 1 git git 393 2009-02-11 14:52 id_rsa.pub
Now we initialize keys to git repository
git$ gitosis-init < .ssh/id_rsa.pub
Initialized empty Git repository in /home/git/repositories/gitosis-admin.git/ Reinitialized existing Git repository in /home/git/repositories/gitosis-admin.git/
Just look at the file permissions it is important the git user has privileges to access data.
git$ ls -al
Same way look at the repositories.
git$ ls -al repositories/
total 12
drwxr-xr-x 3 git git 4096 2009-02-11 14:57 .
drwx------ 7 git git 4096 2009-02-11 14:57 ..
drwxr-x--- 8 git git 4096 2009-02-11 14:57 gitosis-admin.git
Now we are going to clone gitosis-admin.git.
git$ git clone git@localhost:gitosis-admin.git
Initialized empty Git repository in /home/git/gitosis-admin/.git/ Enter passphrase for key '/home/git/.ssh/id_rsa':
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 0), reused 5 (delta 0) Receiving objects: 100% (5/5), done.
Creating New Repositories
Lets allow group persmissions.
git$ ls -al repositories/gitosis-admin.git/hooks/post-update-rw-r--r-- 1 git git 69 2009-02-11 14:57 repositories/gitosis-admin.git/hooks/post-updategit$ chmod 755 repositories/gitosis-admin.git/hooks/post-update
git$ ls -al repositories/gitosis-admin.git/hooks/post-update
-rwxr-xr-x 1 git git 69 2009-02-11 14:57 repositories/gitosis-admin.git/hooks/post-update
Now, Lets take a look at the gitosis-admin source code we checked out .
git$ ls -al gitosis-admin
total 20
drwxr-xr-x 4 git git 4096 2009-02-11 15:38 .
drwx------ 8 git git 4096 2009-02-11 15:49 ..
drwxrwxr-x 8 git git 4096 2009-02-11 15:38 .git
-rw-rw-r-- 1 git git 81 2009-02-11 15:38 gitosis.conf
drwxrwxr-x 2 git git 4096 2009-02-11 15:38 keydir
We can configure gitosis.conf.
git$ cd gitosis-admin
git$ vi gitosis.conf
1 [gitosis]
2
3 [group gitosis-admin]
4 writable = gitosis-admin
5 members = git@localhost
6
7 [group my-staff]
8 writable = my-first-repo
9 members = git@localhost
git$ git commit -a -m "Allow my staff access to my-first-repo"
[master]: created 0c6a685: "Allow my staff access to my-first-repo"
1 files changed, 3 insertions(+), 0 deletions(-)
git$ git push
Enter passphrase for key '/home/git/.ssh/id_rsa':
Counting objects: 5, done.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 381 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@localhost:gitosis-admin.git
7b3ddbe..0c6a685 master -> master
git$ cd
Then we are going to create our first repository.
git$ mkdir my-first-repo
git$ cd my-first-repo
git$ git init
Initialized empty Git repository in /home/git/my-first-repo/.git/
git$ git remote add origin git@localhost:my-first-repo.git
git$ echo "Hello" > README.txt
git$ git add README.txt
git$ git commit -a -m "Initial Revision"
[master (root-commit)]: created 6f567f9: "Initial Revision"
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 README.txt
git$ git push origin master:refs/heads/master
Enter passphrase for key '/home/git/.ssh/id_rsa':
Counting objects: 3, done.
Writing objects: 100% (3/3), 220 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git@localhost:my-first-repo.git
* [new branch] master -> master
git$ cd ..
Now we have new repository,finally we can add new users.
git$ cd gitosis-admin
git$ cp ~/alice.pub keydir
git$ cp ~/bob.pub keydir
git$ git add keydir
git$ vi gitosis.conf
1 [gitosis]
2
3 [group gitosis-admin]
4 writable = gitosis-admin
5 members = git@localhost
6
7 [group my-staff]
8 writable = my-first-repo
9 members = alice bob
git$ git commit -a -m "alice/bob writable to my-first-repo"
[master]: created 17b3295: "alice/bob writable to my-first-repo"
1 files changed, 1 insertions(+), 1 deletions(-)
create mode 100644 keydir/alice.pub
create mode 100644 keydir/bob.pub
git$ git push
Enter passphrase for key '/home/git/.ssh/id_rsa':
Counting objects: 8, done.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 430 bytes, done.
Total 5 (delta 1), reused 0 (delta 0)
To git@magneto:gitosis-admin.git
305600f..17b3295 master -> master
now users can access our central repository.
alice$ git clone git@SERVER_HOSTNAME:my-first-repo.git