HTTP repository sharing asides Gitweb

November 7, 2009

Once you set up Gitweb for HTTP-based Git repository browsing you should also enable (read-only) repository cloning through HTTP. This can be easily done through the use of the AliasMatch directive in Apache.

Assuming a configuration mentioned in my previous post:

  • Apache2 and Gitweb are installed;
  • http://$DOMAIN_BASE/git is Gitweb’s URL,
  • Git repositories are stored in /var/cache/git/

the required steps are:

  1. Run git-update-server-info in the Git repository folder:

    razvan@swarm:~/git-repos/code.git$ git-update-server-info

    This will create the info/refs and objects/info/packs files required by “dumb servers” (as mentioned in the manual page for git-update-server-info).
  2. Add execution rights to the post-update hook:

    razvan@swarm:~/git-repos/code.git$ chmod a+x hooks/post-update

    This hook automatically runs the git-update-server-info at each push.
  3. Add a proper AliasMatch directive to the Apache2 configuration file, before the configuration lines for Gitweb, as shown below:

    AliasMatch ^/git(/.*\.git)(/.*)? /var/cache/git$1$2

    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]

After the above steps are accomplished, one would use the http://$DOMAIN_BASE/git/$REPO.git URL to enable read access to the /var/cache/git/$REPO.git repository:

razvan@valhalla:/tmp$ git clone
Initialized empty Git repository in /tmp/razvan-code/.git/
got 6a3abf757a56cfb3f736c0ebc8f923636151d9c9
walk 6a3abf757a56cfb3f736c0ebc8f923636151d9c9
got 0d60f24cf17c22722307f6163f4d4b2aeee99476

It would be also be nice for the URL to appear in the Gitweb interface. This can be accomplished by adding the @git_base_url_list directive to Gitweb’s configuration file (/etc/gitweb.conf):

swarm:/var/cache/git# tail -2 /etc/gitweb.conf
# git base URL
@git_base_url_list = ('');

Each Git repository entry in the Gitweb interface will now show a label pointing to the HTTP URL for the repository (as can be seen here).

At this point, you can use HTTP for read-only access to the Git repository. Write access is assumed to be accomplished by other means (SSH or others). If you would like write access through HTTP you would have to enable WebDAV support and configuration. JEDI speaks more on this.

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

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

Leave Your Comment



Powered by Wordpress and MySQL. Theme by Shlomi Noach,