Switch from gitweb to cgit

Feb. 18, 2013    Tags: git  gitweb  cgit


I switched my git repository browsing tool from gitweb to cgit.

I haven’t found any really working option to enable caching in gitweb. I have some repositories which are really large. At the moment, one call to the gitweb main (project) page costs a lot of time because the git call to get the latest commit time git for-each-ref —format=’%(committer)’ —sort=-committerdate —count=1 refs/heads

is really time expensive.

First I deleted this section in the gitweb.cgi script. It was much faster, but the possibility to see when the last changes in one repo was done is a must have option to me.

I hosted both. One url for the fast gitweb cgi script and one for the slow cgi script. This was not really a good option to me. So I had a look at alternatives to gitweb and I found cgit.

I describe a short way to host cgit on apache webserver.



  • git (I used Version 1.7.1)
  • apache2 (available as debian/SuSE packages)
  • cgit (available as debian/SuSE packages)

Apache config

If cgit is installed with a debian or SuSE package, all files are on right position. I describe the configuration on SuSE (11.3).

vhosts file

First of all create a vhosts file. I called it repositories.conf and it is located at /etc/apache2/vhosts.d/.


    DirectoryIndex cgit.cgi

    Alias /cgit.png /srv/www/htdocs/cgit/cgit.png
    Alias /cgit.css /srv/www/htdocs/cgit/cgit.css
        AllowOverride none
        Options FollowSymlinks ExecCGI
        Allow from all
        Order allow,deny

        <files cgit.cgi="">
            SetHandler cgi-script

        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^.* /cgit.cgi/$0 [L,PT]

        Options FollowSymlinks Indexes
        Allow from all
        AllowOverride none
        Order allow,deny

Rewrite gitweb URL

I have some links in my bug tracking tool Trac to gitweb commitdiffs. I don’t want to change this old urls. So I have to rewrite this urls to the new cgit one.

Therefore, replace the RewriteRule ^.* /cgit.cgi/$0 [L,PT] with RewriteRule ^(.*)/commitdiff/(.*)$ /cgit\.cgi/$1/commit/?id=$2

load required modules and vhosts

I need the apache module rewrite enabled. To enable it just call a2enmod rewrite.

After that, we have to reload apache: service apache2 reload.

cgit config file

Now I created a cgit config file. It is located at /etc/cgitrc

# Enable caching of up to
1000 output entriess

# Specify some default clone prefixes

# Specify the css url

# Specify the logo url

# Show extra links for each repository on the index page

# Show number of affected files per commit on the log pages

# Show number of added/removed lines per commit on the log pages

# Set the title and heading of the repository index page
root-title=My git repositories
root-desc=containing all git repositories

# Allow download of tar.gz, tar.bz2 and zip-files




## List of common mimetypes

We don’t have to enable the cgitrc explicit. It is loaded automatically by cgit.

Update: The configuration files are now available on GitHub.