1. Home
  2. Tutorials
  3. GitWeb Configuration
Yolinux.com Tutorial

GitWeb Configuration:

Configuration of GitWeb CGI web front-end to a GIT repository.


Gitweb is a web front-end to browse a GIT repository written in Perl. It does not matter how access to the GIT repository is configured (direct on file system, ssh or http), gitweb stands alone and is independent of user accounts and access methods. Gitweb does rely on the Apache httpd web server, Perl and GIT. Gitweb requires read only access to the GIT repository on the file system to browse the artifacts in the repository and display information about the current state of the repository.

Gitweb works directly with the object database, and does not need a clone directory. The name of the project is the name of its repository object database, usually projectname.git for bare repositories. If you want to provide gitweb access to non-bare (live) repositories (example .git), you can make projectname.git a symbolic link under projectroot linking to projectname/.git so that it does not remain a hidden directory.

See our GIT repository server configuration tutorial to generate a GIT repository.

GIT Installation:


  • Apache httpd web server:
    • Red Hat/CentOS/AWS: httpd
    • Ubuntu/Debian: apache2
  • Apache modules: mod_cgi, mod_alias, mod_env, mod_rewrite, mod_dav
    Verify with the command httpd -M or
    CentOS/Red Hat: verify the configuration in /etc/httpd/conf/httpd.conf
    Ubuntu: enable the modules with the command: a2enmod cgi alias env
  • Perl module: Authen::SASL
  • Perl module: GSSAPI
  • Perl module: Term::ReadKey

GIT (Red Hat 6.x RPM Installation:

Install from RPM RHEL6 x86_64 RPM Download GIT 2.12.0
RPMs available:
  • git2u-all - Meta-package to pull in all git tools
  • git2u-core - Core package of git with minimal functionality
    commands: /usr/bin/git, git-receive-pack, git-shell, git-upload-archive, git-upload-pack
  • git2u-core-doc - Documentation files for git-core
    Man pages (1,5,7)
  • git2u-gitweb - Simple web interface to git repositories
    Web front-end: /var/www/git/gitweb.cgi, /etc/gitweb.conf, /etc/httpd/conf.d/git.conf
  • git2u - Fast Version Control System
    man pages for: gitweb, gitweb.conf, git-difftool, git-instaweb
See the EPEL or PBone RPM repositories for dependencies (eg perl-Authen-SASL.noarch, perl-GSSAPI.x86_64, perl-Net-SMTP-SSL.noarch or perl-TermReadKey.x86_64).

Building gitweb from GIT source:

  • make configure
  • ./configure --prefix=/var/www
  • make gitweb
    or make GITWEB_PROJECTROOT="/srv/git/repo" gitweb
    or make GITWEB_PROJECTROOT="/srv/git/repo" GITWEB_CSS="gitweb/static/gitweb.css" gitweb
    When building from source there are a lot of configurable parameters associated with file directory locations.
  • sudo make gitwebdir=/var/www/cgi-bin install-gitweb

GitWeb Configuration:

Red Hat/CentOS/Fedora:

Gitweb as installed by an RPM:

  • /etc/gitweb.conf
  • /var/www/git/gitweb.cgi - Gitweb Perl CGI
  • /var/www/git/static/...

For more information see /usr/share/doc/git2u-gitweb-2.10.2/INSTALL

Apache httpd web server configuration:

File: /etc/httpd/conf.d/gitweb.conf
Alias /gitweb /var/www/git

# Allow execution of CGI
<Directory /var/www/git>
  Options +ExecCGI
  AddHandler cgi-script .cgi
  DirectoryIndex gitweb.cgi

<Location "/gitweb">
  AuthType Basic
  AuthName "Megacorp directory services login"
  AuthBasicProvider ldap
  AuthzLDAPAuthoritative on
  AuthLDAPURL "ldap://ldap.megacorp.com:389/ou=person,o=megacorp.com,c=us?uid?sub"
  Require ldap-user user1 user2

GitWeb Configuration:

File: /etc/gitweb.conf
$projectroot = "/srv/git/repo";
# This just makes the description field wider so you can read it better
$projects_list_description_width = 100;
$feature{'blame'}{'default'} = [1];
$feature{'grep'}{'default'} = [0];
  • where the "projectroot" is the parent directory of a GIT repository or of multiple GIT repositories. This will cover /srv/git/repo/projectx.git and /srv/git/repo/projecty.git
  • Use symbolic links to place all repositories under the same heirarchy if the repositories are scattered throughout the file system.
  • Set to "1" to turn on feature and "0" to turn off the feature.

The full configuration file and comments are as follows:

# The gitweb config file is a fragment of perl code. You can set variables
# using "our $variable = value"; text from "#" character until the end of a
# line is ignored. See perlsyn(1) man page for details.
# See /usr/share/doc/gitweb-*/README and /usr/share/doc/gitweb-*/INSTALL for
# more details and available configuration variables.

# Set the path to git projects.  This is an absolute filesystem path which will
# be prepended to the project path.
#our $projectroot = "/var/lib/git";
$projectroot = "/srv/git/repo";

# Set the list of git base URLs used for URL to where fetch project from, i.e.
# the full URL is "$git_base_url/$project". By default this is empty
#our @git_base_url_list = qw(git://git.example.com
#                            ssh://git.example.com/var/lib/git);

# Enable the 'blame' blob view, showing the last commit that modified
# each line in the file. This can be very CPU-intensive. Disabled by default
$feature{'blame'}{'default'} = [1];
# Allow projects to override the default setting via git config file.
# Example: gitweb.blame = 0|1;
#$feature{'blame'}{'override'} = 1;

# Disable the 'snapshot' link, providing a compressed archive of any tree. This
# can potentially generate high traffic if you have large project. Enabled for
# .tar.gz snapshots by default.
# Value is a list of formats defined in %known_snapshot_formats that you wish
# to offer.
#$feature{'snapshot'}{'default'} = [];
# Allow projects to override the default setting via git config file.
# Example: gitweb.snapshot = tbz2,zip; (use "none" to disable)
#$feature{'snapshot'}{'override'} = 1;

# Disable grep search, which will list the files in currently selected tree
# containing the given string. This can be potentially CPU-intensive, of
# course. Enabled by default.
$feature{'grep'}{'default'} = [0];
# Allow projects to override the default setting via git config file.
# Example: gitweb.grep = 0|1;
#$feature{'grep'}{'override'} = 1;

# Disable the pickaxe search, which will list the commits that modified a given
# string in a file. This can be practical and quite faster alternative to
# 'blame', but still potentially CPU-intensive. Enabled by default.
#$feature{'pickaxe'}{'default'} = [0];
# Allow projects to override the default setting via git config file.
# Example: gitweb.pickaxe = 0|1;
#$feature{'pickaxe'}{'override'} = 1;
Restart web server to pick up the configuration changes:
  • Ubuntu: apache2ctl -k graceful
  • RedHat: service httpd restart

SeLinux Configuration:

SeLinux can be turned off: setenforce 0

For a more secure configuration, leave SeLinux turned on (setenforce 1) and configure as follows:
  • Allow the Apache web server to read the GIT repository: chcon -R system_u:object_r:git_sys_content_t:s0 /srv/git/repo
    or use the intended, system pre-configured GIT repository directory /var/lib/git/
  • Allow gitweb to access support files: chcon -R system_u:object_r:httpd_git_content_t:s0 /var/www/git/
    (Usually configured by the RPM installation)
  • Allow the Apache web server to execute the CGI: chcon system_u:object_r:httpd_git_script_exec_t:s0 /var/www/git/gitweb.cgi
View selinux file contexts with the command: ls -lZ

GIT Man Pages:
  • gitweb - Git web interface (web front-end to Git repositories)
  • git instaweb - Instantly browse your working repository in gitweb
  • git
  • git help - Display help information about Git

Repository Home Page:

The final touch is to create a homepage for your web viewable repositories so that they are easy to find, especially if you are hosting multiple reporitories. The default homepage for most major Linux distributions (Red Hat, Fedora, CentOS, Ubuntu, Debian) is /var/www/html/index.html Create a home page here or create a redirect to the Trac Wiki home page and post links there.

Redirect web server default to the Trac Wiki
<META HTTP-EQUIV="Refresh" Content="0; URL=/trac/projectx">
or generate a Software CM home page.

Sample home page:
<title>Welcome to Project X</title>
<h1>Welcome to Project X</h1>

<li> <a href="/trac/projectx">Trac Wiki</a> </li>
<li> <a href="/gitweb/">Git-web</a> </li>
<li> <a href="/jenkins">Jenkins</a> </li>


Book imageBooks:

"Version Control With Git"
by Jon Loeliger
ISBN #1449316387, O'Reilly Media; 2 edition (August 27, 2012)

Distributed Version Control with Git [Kindle Edition]
Lars Vogel (Author)
A practical introduction into the Git version control system.

Pro Git
Scott Chacon (Author)
Visual explanations of the git concepts and methodology.

Step-by-step ways to track, merge, and manage software projects, using Git.