Gitweb

From ArchWiki

Gitweb is the default web interface that comes with Git.

Gitweb actually supports FCGI natively, so you do not need to wrap it as a CGI script.[1]

Installation

To install Gitweb you first have to install git and a web server. Now, if you want to quickly test it, see the help of git instaweb. Otherwise, if you want a comprehensive setup, keep reading.

For all the examples below, you need to install the perl-cgi package. (FS#45431)

Configuration of web server

Apache

Add the following to the end of your /etc/httpd/conf/httpd.conf:

Alias /gitweb "/usr/share/gitweb"
<Directory "/usr/share/gitweb">
   DirectoryIndex gitweb.cgi
   Options ExecCGI
   Require all granted
   <Files gitweb.cgi>
   SetHandler cgi-script
   </Files>
   SetEnv  GITWEB_CONFIG  /etc/gitweb.conf
</Directory>

or alternatively add it to a separate file like etc/httpd/conf/extra/gitweb.conf and then add the following to the end of httpd.conf:

# gitweb configuration
Include conf/extra/gitweb.conf

If Apache refuses to display Gitweb, but prints the plain source code of the perl script instead, it is very likely that Apache is not configured to permit CGI execution. Make sure that the following is uncommented in httpd.conf:

<IfModule !mpm_prefork_module>
   LoadModule cgid_module modules/mod_cgid.so
</IfModule>
<IfModule mpm_prefork_module>
   LoadModule cgi_module modules/mod_cgi.so
</IfModule>

then restart httpd.service to apply these changes. For further details about CGI execution with Apache, see https://httpd.apache.org/docs/2.4/howto/cgi.html.

Lighttpd

Add the following to /etc/lighttpd/lighttpd.conf:

server.modules += ( "mod_alias", "mod_cgi", "mod_redirect", "mod_setenv" )
url.redirect += ( "^/gitweb$" => "/gitweb/" )
alias.url += ( "/gitweb/" => "/usr/share/gitweb/" )
$HTTP["url"] =~ "^/gitweb/" {
       setenv.add-environment = (
               "GITWEB_CONFIG" => "/etc/gitweb.conf",
               "PATH" => env.PATH
       )
       cgi.assign = ( ".cgi" => "" )
       server.indexfiles = ( "gitweb.cgi" )
}

then restart lighttpd.service to apply these changes. You may also need to add ".css" => "text/css" to the mimetype.assign line for GitWeb to display properly.

Nginx

Append this location to your nginx configuration (you might want to change the location):

/etc/nginx/nginx.conf
location /gitweb.cgi {
    include fastcgi_params;
    gzip off;
    fastcgi_param   SCRIPT_FILENAME  /usr/share/gitweb/gitweb.cgi;
    fastcgi_param   GITWEB_CONFIG  /etc/gitweb.conf;
    fastcgi_pass    unix:/run/fcgiwrap.sock;
}

location / {
    root /usr/share/gitweb;
    index gitweb.cgi;
}

If you follow Nginx#CGI implementation, try replacing include fastcgi_params; with include fastcgi.conf;.

Finally, install fcgiwrap and start/enable fcgiwrap.socket.

Configuration of Gitweb

See gitweb.conf(5) for the list of all configuration options.

Basic configuration

Open (or create if it does not exist) the file /etc/gitweb.conf and place this in it:

/etc/gitweb.conf
# The directories where your projects are. Must not end with a slash.
our $projectroot = "/path/to/your/repositories"; 

# Base URLs for links displayed in the web interface.
our @git_base_url_list = qw(git://<your_server> http://git@<your_server>);

To enable "blame" view (showing the author of each line in a source file), add the following line:

$feature{'blame'}{'default'} = [1];

Now that the configuration is done, restart your web server.

Adding repositories

To add a repository go to your repository folder, make your repository like so:

$ mkdir my_repository.git
$ git init --bare my_repository.git/
$ cd my_repository.git/
$ touch git-daemon-export-ok
$ echo "Short project's description" > description

Next open the gitweb.config file and add this:

gitweb.config
[gitweb]
owner = Your Name

This will fill in the "Owner" field in Gitweb. It is not required.

This assumes that you want to have this repository as "central" repository storage where you push your commits to so the git-daemon-export-ok and --bare are here to have minimal overhead and to allow the git daemon to be used on it.

That is all for making a repository. You can now see it on your http://localhost/gitweb (assuming everything went fine). You do not need to restart Apache for new repositories since the Gitweb CGI script simply reads your repository folder.

Syntax highlighting

To enable syntax highlighting with Gitweb, you have to first install the highlight package:

When highlight has been installed, simply add this line to your gitweb.conf:

$feature{'highlight'}{'default'} = [1];

Save the file and highlighting should now be enabled.

See also