I have set up Git on a server, using gitosis to control commit access. I would like to configure my Git system so that anyone inside our firewall can have read access to the Git repository, and I would like to set up Gitweb as well.

I have found several Gitweb setup tutorials on various blogs, but they differ in various details and some of them are out-of-date. I'd like this question to have an up-to-date answer.

My specific setup is Red Hat Enterprise Linux. I have successfully installed Git, gitosis, and the Gitweb and Apache packages. However, I have not figured out how to configure Apache to actually grant access to Gitweb.

How do I set up my server to allow read-only access to Git, and to allow Gitweb to work?


After you install gitweb (on RHEL $ yum install gitweb), it should create a directory var/www/git and put a file in etc/httpd/conf.d/git.conf. If these don't exist, create them. Put all your git repos in var/www/git and edit git.conf to let it execute cgi scripts and rewrite URLs for gitweb. Here's what I have:

<Directory /var/www/git>
SetEnv  GITWEB_CONFIG  /etc/gitweb.conf
DirectoryIndex gitweb.cgi
Allow from all
AllowOverride all
Order allow,deny
Options +ExecCGI
AddHandler cgi-script .cgi
<Files gitweb.cgi>
  SetHandler cgi-script
RewriteEngine on
RewriteRule ^[a-zA-Z0-9_-]+.git/?(\?.)?$ /gitweb.cgi%{REQUESTURI} [L,PT]

There is also a gitweb.conf file in /etc/gitweb.conf which points to things like css, favicons and logos. I'm pretty sure those will work if you leave your projects in /var/www/git, but if you change that directory, you'll probably need to put it in gitweb.conf.

  • What will the URL be to access it? Will it be like so: server_name_goes_here/gitweb – steveha Oct 9 '09 at 5:15
  • If your document root in httpd.conf is /var/www, then it will be domain.com/gitweb. If you want to serve git from a subdomain to do something like git.domain.com, you'll have to set up a VirtualHost around that <Directory> – al. Oct 9 '09 at 5:22
  • Sorry, I mean, it will be domain.com/git (according to the version of git.conf i put above) – al. Oct 9 '09 at 5:24

Tested out on Ubuntu 8.04:

sudo apt-get install apache2 git-core gitweb
sudo a2enmod rewrite

Assuming that you git projects are in /pub/git, edit the file: /etc/gitweb.conf

$projectroot = "/pub/git";
$git_temp = "/tmp";
#$home_link = $my_uri || "/";
$home_text = "indextext.html";
$projects_list = $projectroot;
$stylesheet = "/gitweb.css";
$logo = "/git-logo.png";
$favicon = "/git-favicon.png";
# enable human readable URLs
$feature{'pathinfo'}{'default'} = [1];

Now, setup a new virtual host in Apache config directory. Edit a new file called: /etc/apache2/sites-available/gitweb

<VirtualHost *>
   ServerName     git.mydomain.com
   ServerAlias    git

   DocumentRoot /pub/git
   SetEnv GITWEB_CONFIG /etc/gitweb.conf

   RewriteEngine on
   RewriteRule ^/$                                            /gitweb [PT]
   RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /gitweb%{REQUEST_URI}  [L,PT]

   # Aliases
   ScriptAlias /gitweb           /usr/lib/cgi-bin/gitweb.cgi
   Alias       /gitweb.css       /usr/share/gitweb/gitweb.css
   Alias       /git-logo.png     /usr/share/gitweb/git-logo.png
   Alias       /git-favicon.png  /usr/share/gitweb/git-favicon.png

   # Logfiles
   ErrorLog  /var/log/apache2/gitweb.error.log
   CustomLog /var/log/apache2/gitweb.access.log combined

Enable the new site:

sudo a2ensite gitweb

Restart Apache:

sudo invoke-rc.d apache2 restart
  • /etc/apache2/sites-available# sudo service apache2 restart Syntax error on line 10 of /etc/apache2/sites-enabled/gitweb: RewriteRule: bad flag delimiters Action 'configtest' failed. The Apache error log may have more information. ...fail! – Marcel Burkhard Feb 16 '15 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.