HOWTO create GIT repository for Trac on Debian

Setting up a public GIT repository is a bit complicated when compare with my previous CVS experience. From 8 ways to share your git repository I choose to use gitosis as solution when combine with Trac. The following material are mainly based on Hosting Git repositories, The Easy (and Secure) Way. We will also install git-daemon-run for anonymous public access.

Install gitosis and related packages in Debian

Just simply run:

apt-get install gitosis git git-core git-daemon-run sudo

Create and initialize SSH key for gitosis

Next we should create the SSH public by:

hswong3i:~# sudo -H -u gitosis ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/srv/gitosis/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /srv/gitosis/.ssh/id_rsa. Your public key has been saved in /srv/gitosis/.ssh/id_rsa.pub. The key fingerprint is: fd:79:66:50:35:1e:29:9b:8a:f4:04:c1:4b:b0:b7:10 gitosis@hswong3i.edin.no-ip.com The key's randomart image is: +--[ RSA 2048]----+ | Eo.. oo| | o+ ..oo| | o..o =. | | o+.. + | | S.= o | | . + o | | o + | | + | | | +-----------------+ hswong3i:~#

Now initialize gitosis-admin repository with following command:

hswong3i:~# sudo -H -u gitosis gitosis-init

Setting up with gitosis.conf

Next is the magic of gitosis, run the following command under /tmp:

hswong3i:/tmp# git clone gitosis@localhost:gitosis-admin Initialized empty Git repository in /tmp/gitosis-admin/.git/ The authenticity of host 'localhost (127.0.0.1)' can't be established. RSA key fingerprint is 90:9f:31:e7:56:49:93:95:7f:67:11:6a:2a:eb:6e:ce. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'localhost' (RSA) to the list of known hosts. Receiving objects: 100% (5/5), done. remote: Counting objects: 5, done. Resolving deltas: 100% (1/1), done.3/4)Resolving deltas: 100% (1/1) remote: Compressing objects: 100% (4/4), done. remote: Total 5 (delta 1), reused 5 (delta 1) hswong3i:/tmp# ls -la gitosis-admin/ total 20 drwxr-xr-x 4 root root 4096 2010-09-22 12:52 . drwxrwxrwt 6 root root 4096 2010-09-22 12:52 .. drwxr-xr-x 8 root root 4096 2010-09-22 12:52 .git -rw-r--r-- 1 root root 98 2010-09-22 12:52 gitosis.conf drwxr-xr-x 2 root root 4096 2010-09-22 12:52 keydir hswong3i:/tmp#

You will get the directory gitosis-admin and let's edit the gitosis.conf as below:

[gitosis] gitweb = yes daemon = yes loglevel = DEBUG [group gitosis-admin] writable = gitosis-admin members = root@hswong3i.edin.no-ip.com [group example.com] writable = example.com members = root@hswong3i.edin.no-ip.com [repo example.com] owner = example.com description = example.com sample project repository.

Save the changes, commit and push it:

hswong3i:/tmp/gitosis-admin# git commit -a -m '- add example.com sample project repository.' hswong3i:/tmp/gitosis-admin# git push

Create and initialize the new repository

Its time to create and initialize our new repository:

hswong3i:/tmp# cd /tmp/ hswong3i:/tmp# mkdir example.com hswong3i:/tmp# cd example.com/ hswong3i:/tmp/example.com# git init hswong3i:/tmp/example.com# git remote add origin gitosis@localhost:example.com.git hswong3i:/tmp/example.com# touch README.txt hswong3i:/tmp/example.com# git add README.txt hswong3i:/tmp/example.com# git commit -a -m '- add README.txt.' hswong3i:/tmp/example.com# git push origin master:refs/heads/master

Check the result:

hswong3i:/tmp/example.com# git log

Create and initialize new Trac project with GIT support

Here I will just skip the installation of Trac and assume you have get it up correctly. It is a bit complicated and so will not detail here. I am using WSGI now and all sites are hosted under /srv/trac/sites

Let's create a new project for trac now. Go to /srv/trac/sites and create a new Trac project directory:

hswong3i:~# mkdir -p /srv/trac/sites/example.com hswong3i:~# cd /srv/trac/sites/example.com hswong3i:/srv/trac/sites/example.com# trac-admin . initenv

During the interactive installation, answer some key question as below:

Repository type [svn]> git Path to repository [/path/to/repos]> /srv/gitosis/repositories/example.com.git

Assume you have setup support with GIT correctly, now your new Trac project should able to browse with the GIT repository. Enjoy :D

Comments

root's picture

Can you format this so that the line breaks show up properly?

The link on this page was useful though! They have a nice guide.
Thanks!

Add new comment