Gitweb access to Git repositories

November 7, 2009

I’ve recently spent some time configuring Gitweb access to Git repositories. It took me a while to find out how it worked as the configuration interface has changed since its first release and older blog entries were mentioning it. At first there was a Perl configuration script (gitweb-config.pl) but nowadays the common way to configure Gitweb is through a simple configuration file (gitweb.conf).

For a typical Debian installation (apt-get install gitweb), all that is required is to create or link repositories in the default Debian Git repository root (/var/cache/git/) and add some lines to an Apache configuration file. The default configuration file for Gitweb (/etc/gitweb.conf) works out of the box. The first directive ($projectroot) points to the Git repository root. If you would like your Git repositories to reside somewhere else, just alter $projectroot:

# path to git projects ( .git)
$projectroot = "/var/cache/git";
[...]

Assuming you would want the http://$DOMAIN_BASE/git URL to enable the Gitweb interface, there are two steps you should do:

  1. Create the /var/www/gitweb/ folder and create symlinks for /usr/share/gitweb/git-favicon.png, /usr/share/gitweb/gitweb.css, /usr/share/gitweb/git-logo.png and /usr/lib/cgi-bin.cgi. You should end up with something like this:

    $ ls -l /var/www/gitweb/
    total 0
    lrwxrwxrwx 1 root root 33 2009-11-05 21:25 git-favicon.png -> /usr/share/gitweb/git-favicon.png
    lrwxrwxrwx 1 root root 30 2009-11-05 21:26 git-logo.png -> /usr/share/gitweb/git-logo.png
    lrwxrwxrwx 1 root root 27 2009-11-05 21:26 gitweb.cgi -> /usr/lib/cgi-bin/gitweb.cgi
    lrwxrwxrwx 1 root root 28 2009-11-05 21:26 gitweb.css -> /usr/share/gitweb/gitweb.css

  2. Add the following configuration line to a proper Apache configuration file (either a configuration file in /etc/apache2/conf.d/ or a site file in /etc/apache2/sites-enabled/):

    Alias /git /var/www/gitweb/
    <Directory /var/www/gitweb/>
    Options ExecCGI FollowSymLinks
    AddHandler cgi-script cgi
    DirectoryIndex gitweb.cgi

    RewriteEngine On
    RewriteRule ^/git$ /git/gitweb.cgi
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/git/.* /git/gitweb.cgi/$0 [L,PT]
    </Directory>

All you have to do now is add Git repositories to the Git repository root (in my case /var/cache/git/). I prefer using symlinks as most Git repositories me and my friends are using are stored in our home folders:

swarm:~# cd /var/cache/git/
swarm:/var/cache/git# ln -sf /home/razvan/git-repos/code.git/ razvan-code.git
swarm:/var/cache/git# ls -l
total 0
lrwxrwxrwx 1 root root 32 Nov 7 12:37 razvan-code.git -> /home/razvan/git-repos/code.git/

In the end you’ll end up with a cool web interface (similar to this) to your (and your friends’) Git repositories to share with the world. Cool!

tags: , , , ,
posted in Administration by Răzvan Deaconescu

Follow comments via the RSS Feed | Leave a comment | Trackback URL

1 Comment to "Gitweb access to Git repositories"

  1. catalin.me wrote:

    Worked for me only when I had somenthing like this in /etc/gitweb.conf:

    $stylesheet = “/git/gitweb.css”;
    $logo = “/git/git-logo.png”;
    $favicon = “/git/git-favicon.png”;

    Great tutorial btw !

    [Reply]

Leave Your Comment

*

*

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org