Tag: ubuntu

Browse your personal Git repository online

After installing a Git repository on a webserver I’d also like to browse it using my webbrowser. We can do this via the gitweb package and some additional configuration in Apache. The assumption is that this is done on a Ubuntu system.

The result will be that repositories can be cloned via /git/repos/[name].git and browsed via /git/, within the same VirtualHost. It is assumed that your VirtualHost is set up similar to the previous blog post on git on this blog.

First install gitweb via the apt-get package manager:

apt-get install gitweb

The configuration for gitweb is located at _/etc/gitweb.conf. _Only one line needs to be changed, at the beginning of the file; change the $projectroot value to the root of your git repository.:

# path to git projects (<project>.git)
$projectroot = "/var/git/repository";

The installation of the gitweb packace has placed a configuration file in /etc/apache2/conf.d/gitweb:

Alias /gitweb /usr/share/gitweb
<Directory /usr/share/gitweb>
	Options FollowSymLinks +ExecCGI
	AddHandler cgi-script .cgi
</Directory>

This causes the URL /gitweb/ to be mapped to the gitweb script, causing it to show up on every VirtualHost. We want it to show up only on the git.example.com VirtualHost. In order to do so, remove this configuration file. Modify the git.example.com (or any VirtualHost you have configured for git access) and add the following lines:

Alias /git /usr/share/gitweb
<Directory /usr/share/gitweb>
	Options FollowSymLinks +ExecCGI
	AddHandler cgi-script .cgi
</Directory>

Also remove the line

#ScriptAlias /git/ /usr/lib/git-core/git-http-backend/

and replace it with:

ScriptAliasMatch \
	"(?x)^/git/(.\*/(HEAD | \
	info/refs | \
	objects/(info/\[^/\]+ | \
	\[0-9a-f\]{2}/\[0-9a-f\]{38} | \
	pack/pack-\[0-9a-f\]{40}\\.(pack|idx)) | \
	git-(upload|receive)-pack))$" \
	/usr/lib/git-core/git-http-backend/$1

This causes all requests from the git commandline (push, pull, clone, etc) to be forwarded to the git-http-backend script, while all other requests are handled by gitweb.

Leave a Comment