Prerequisite
Install
gitsudo apt-get install git-core
Initializing gitosis
Grab
gitosiskamal@dev:~$ git clone git://eagain.net/gitosis.git Initialized empty Git repository in /home/kamal/gitosis/.git/ remote: Generating pack... remote: Done counting 549 objects. remote: Deltifying 549 objects... remote: 100% (549/549) done Indexing 549 objects... remote: Total 549 (delta 379), reused 136 (delta 95) 100% (549/549) done Resolving 379 deltas... 100% (379/379) doneInstall
gitosiskamal@dev:~/gitosis$ cd gitosis && sudo python setup.py install running install running bdist_egg running egg_info creating gitosis.egg-info ... Installing gitosis-init script to /usr/bin Installing gitosis-run-hook script to /usr/bin Installing gitosis-serve script to /usr/bin Installed /usr/lib/python2.4/site-packages/gitosis-0.2-py2.4.egg Processing dependencies for gitosis==0.2 Finished processing dependencies for gitosis==0.2Create the
gituser on the serverkamal@dev:~$ sudo adduser \ > --system \ > --shell /bin/sh \ > --gecos 'git version control' \ > --group \ > --disabled-password \ > --home /var/local/git \ > git Adding system user `git' (UID 106) ... Adding new group `git' (GID 109) ... Adding new user `git' (UID 106) with group `git' ... Creating home directory `/var/local/git' ...Back on your local machine,
scpyour SSH public key to the serverMacBook-Pro:~ kamal$ scp ~/.ssh/id_dsa.pub dev.ror.com.my:/tmp id_dsa.pub 100% 613 0.6KB/s 00:00Back on the server, initialize
gitosiskamal@dev:~/gitosis$ sudo -H -u git gitosis-init < /tmp/id_dsa.pub Initialized empty Git repository in ./ Initialized empty Git repository in ./Back on your local machine, clone the automatically created
gitosis-adminprojectMacBook-Pro:~ kamal$ git clone git@dev.ror.com.my:gitosis-admin.git Initialized empty Git repository in /Users/kamal/gitosis-admin/.git/ remote: Generating pack... remote: Done counting 5 objects. remote: Deltifying 5 objects... remote: 100% (5/5) done remote: Total 5 (delta 1), reused 5 (delta 1) Indexing 5 objects... 100% (5/5) done Resolving 1 deltas... 100% (1/1) doneCheck out the contents of
gitosis-adminMacBook-Pro:~ kamal$ cd gitosis-admin/ MacBook-Pro:gitosis-admin kamal$ ls gitosis.conf keydir MacBook-Pro:gitosis-admin kamal$ more gitosis.conf [gitosis] [group gitosis-admin] writable = gitosis-admin members = kamal@MacBook-Pro.local MacBook-Pro:gitosis-admin kamal$ ls keydir/ kamal@MacBook-Pro.local.pubNote: The main configuration file lives in
gitosis.confand the users are identified by their SSH public keys which are inkeydir
Adding Users
Adding Aizat as a gitosis-admin member is easy
MacBook-Pro:gitosis-admin kamal$ cp /tmp/aizat-id_dsa.pub keydir/aizat@Zatto.local.pubNote: The filename in the keydir has to match the last bit in the public key file plus
.pubEdit gitosis.conf
[gitosis] [group gitosis-admin] writable = gitosis-admin members = kamal@MacBook-Pro.local aizat@Zatto.localAdd the new file to git
MacBook-Pro:gitosis-admin kamal$ git add keydir/aizat\@Zatto.local.pubCommit the changes
MacBook-Pro:gitosis-admin kamal$ git-commit -a -m "Added Aizat as a gitosis admin" Created commit 37c0966: Added Aizat as a gitosis admin 2 files changed, 2 insertions(+), 1 deletions(-) create mode 100644 keydir/aizat@Zatto.local.pubAnd push to the server
MacBook-Pro:gitosis-admin kamal$ git push updating 'refs/heads/master' from 3b5462b027a02a5b29bf43f4ca878350ccc8b913 to 37c0966f285715cc38bd801a3955bb6f319ccdf4 Also local refs/remotes/origin/master Generating pack... Done counting 8 objects. Result has 5 objects. Deltifying 5 objects... 100% (5/5) done Writing 5 objects... 100% (5/5) done Total 5 (delta 1), reused 0 (delta 0) refs/heads/master: 3b5462b027a02a5b29bf43f4ca878350ccc8b913 -> 37c0966f285715cc38bd801a3955bb6f319ccdf4To add non-admin users, the process is the roughly the same. You only need to create a new group in
gitosis.conf.
Adding Projects
Add a new group for other users and set a new test project as the writable project
[gitosis] [group gitosis-admin] writable = gitosis-admin members = kamal@MacBook-Pro.local aizat@Zatto.local [group rsb] writable = test_project members = @gitosis-admin kegan@MacBook.local saimer@MacBook.local seanx2@Dell.localCommit and push
MacBook-Pro:gitosis-admin kamal$ git-commit -a -m "Added a new group for RSB and set write perms on a new test project" MacBook-Pro:gitosis-admin kamal$ git push updating 'refs/heads/master' from 37c0966f285715cc38bd801a3955bb6f319ccdf4 to 2fc5d9c394218fb757ce6fe468b9ea8096e99dcf Also local refs/remotes/origin/master Generating pack... Done counting 8 objects. Result has 6 objects. Deltifying 6 objects... 100% (6/6) done Writing 6 objects... 100% (6/6) done Total 6 (delta 1), reused 0 (delta 0) refs/heads/master: 37c0966f285715cc38bd801a3955bb6f319ccdf4 -> 2fc5d9c394218fb757ce6fe468b9ea8096e99dcfCreate the test project
MacBook-Pro:~ kamal$ mkdir test_project MacBook-Pro:~ kamal$ cd test_project/ MacBook-Pro:test_project kamal$ git init Initialized empty Git repository in .git/ MacBook-Pro:test_project kamal$ git remote add origin git@dev.ror.com.my:test_project.git MacBook-Pro:test_project kamal$ echo "This is an test project hosted in git" > README MacBook-Pro:test_project kamal$ git add README MacBook-Pro:test_project kamal$ git commit -a -m "Added a README file" Created initial commit f70c2f7: Added a README file 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 READMENote: It is important that you have files to add, otherwise the next command will fail. I think this has to do with
gitnot tracking empty directories?Push the test_project to the server
MacBook-Pro:test_project kamal$ git push origin master:refs/heads/master updating 'refs/heads/master' from 0000000000000000000000000000000000000000 to f70c2f74d71fbbb1edd0f5da2554fd208f75051b Also local refs/remotes/origin/master Generating pack... Done counting 3 objects. Deltifying 3 objects... 100% (3/3) done Writing 3 objects... 100% (3/3) done Total 3 (delta 0), reused 0 (delta 0) refs/heads/master: 0000000000000000000000000000000000000000 -> f70c2f74d71fbbb1edd0f5da2554fd208f75051bTest out by cloning the project
MacBook-Pro:~ kamal$ git clone git@dev.ror.com.my:test_project.git test_project2 Initialized empty Git repository in /Users/kamal/test_project2/.git/ remote: Generating pack... remote: Done counting 3 objects. remote: Deltifying 3 objects... remote: 100% (3/3) done remote: Total 3 (delta 0), reused 0 (delta 0) Indexing 3 objects... 100% (3/3) done
And you’re done!
In the next article, I will explore migrating existing Subversion repositories to git. Stay tuned!
Leave a Reply

