<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">

<sect2 lang="en" id="gitweb(1)">
    <title>gitweb(1)</title>
    <date>2024-07-02</date>
<revhistory><revision><date>2024-07-02</date></revision></revhistory>
<indexterm>
<primary>gitweb(1)</primary>
</indexterm>
<simplesect id="gitweb(1)__name">
<title>NAME</title>
<simpara>gitweb - Git web interface (web frontend to Git repositories)</simpara>
</simplesect>
<simplesect id="gitweb(1)__synopsis">
<title>SYNOPSIS</title>
<simpara>To get started with gitweb, run <xref linkend="git-instaweb(1)" /> from a Git repository.
This will configure and start your web server, and run a web browser pointing to
gitweb.</simpara>
</simplesect>
<simplesect id="gitweb(1)__description">
<title>DESCRIPTION</title>
<simpara>Gitweb provides a web interface to Git repositories.  Its features include:</simpara>
<itemizedlist>
<listitem>
<simpara>
Viewing multiple Git repositories with common root.
</simpara>
</listitem>
<listitem>
<simpara>
Browsing every revision of the repository.
</simpara>
</listitem>
<listitem>
<simpara>
Viewing the contents of files in the repository at any revision.
</simpara>
</listitem>
<listitem>
<simpara>
Viewing the revision log of branches, history of files and directories,
  seeing what was changed, when, and by whom.
</simpara>
</listitem>
<listitem>
<simpara>
Viewing the blame/annotation details of any file (if enabled).
</simpara>
</listitem>
<listitem>
<simpara>
Generating RSS and Atom feeds of commits, for any branch.
  The feeds are auto-discoverable in modern web browsers.
</simpara>
</listitem>
<listitem>
<simpara>
Viewing everything that was changed in a revision, and stepping through
  revisions one at a time, viewing the history of the repository.
</simpara>
</listitem>
<listitem>
<simpara>
Finding commits whose commit messages match a given search term.
</simpara>
</listitem>
</itemizedlist>
<simpara>See <ulink url="https://repo.or.cz/w/git.git/tree/HEAD:/gitweb/">https://repo.or.cz/w/git.git/tree/HEAD:/gitweb/</ulink> for gitweb source code,
browsed using gitweb itself.</simpara>
</simplesect>
<simplesect id="gitweb(1)__configuration">
<title>CONFIGURATION</title>
<simpara>Various aspects of gitweb's behavior can be controlled through the configuration
file <emphasis>gitweb_config.perl</emphasis> or <emphasis>/etc/gitweb.conf</emphasis>.  See the <xref linkend="gitweb.conf(5)" />
for details.</simpara>
<section id="gitweb(1)__repositories">
<title>Repositories</title>
<simpara>Gitweb can show information from one or more Git repositories.  These
repositories have to be all on local filesystem, and have to share a common
repository root, i.e. be all under a single parent repository (but see also
the "Advanced web server setup" section, "Webserver configuration with multiple
projects' root" subsection).</simpara>
<screen>our $projectroot = '/path/to/parent/directory';</screen>
<simpara>The default value for <emphasis>$projectroot</emphasis> is <emphasis>/pub/git</emphasis>.  You can change it during
building gitweb via the <emphasis>GITWEB_PROJECTROOT</emphasis> build configuration variable.</simpara>
<simpara>By default all Git repositories under <emphasis>$projectroot</emphasis> are visible and available
to gitweb.  The list of projects is generated by default by scanning the
<emphasis>$projectroot</emphasis> directory for Git repositories (for object databases to be
more exact; gitweb is not interested in a working area, and is best suited
to showing "bare" repositories).</simpara>
<simpara>The name of the repository in gitweb is the path to its <emphasis>$GIT_DIR</emphasis> (its object
database) relative to <emphasis>$projectroot</emphasis>.  Therefore the repository $repo can be
found at "$projectroot/$repo".</simpara>
</section>
<section id="gitweb(1)__projects_list_file_format">
<title>Projects list file format</title>
<simpara>Instead of having gitweb find repositories by scanning the filesystem
starting from $projectroot, you can provide a pre-generated list of
visible projects by setting <emphasis>$projects_list</emphasis> to point to a plain text
file with a list of projects (with some additional info).</simpara>
<simpara>This file uses the following format:</simpara>
<itemizedlist>
<listitem>
<simpara>
One record (for project / repository) per line; does not support line
continuation (newline escaping).
</simpara>
</listitem>
<listitem>
<simpara>
Leading and trailing whitespace are ignored.
</simpara>
</listitem>
<listitem>
<simpara>
Whitespace separated fields; any run of whitespace can be used as field
separator (rules for Perl's "<emphasis>split(" ", $line)</emphasis>").
</simpara>
</listitem>
<listitem>
<simpara>
Fields use modified URI encoding, defined in RFC 3986, section 2.1
(Percent-Encoding), or rather "Query string encoding" (see
<ulink url="https://en.wikipedia.org/wiki/Query_string#URL_encoding">https://en.wikipedia.org/wiki/Query_string#URL_encoding</ulink>), the difference
being that SP (" ") can be encoded as "&#43;" (and therefore "&#43;" has to be
also percent-encoded).
</simpara>
<simpara>Reserved characters are: "%" (used for encoding), "&#43;" (can be used to
encode SPACE), all whitespace characters as defined in Perl, including SP,
TAB and LF, (used to separate fields in a record).</simpara>
</listitem>
<listitem>
<simpara>
Currently recognized fields are:
</simpara>
<variablelist>
<varlistentry>
<term>
&lt;repository path&gt;
</term>
<listitem>
<simpara>
        path to repository GIT_DIR, relative to <emphasis>$projectroot</emphasis>
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
&lt;repository owner&gt;
</term>
<listitem>
<simpara>
        displayed as repository owner, preferably full name, or email,
        or both
</simpara>
</listitem>
</varlistentry>
</variablelist>
</listitem>
</itemizedlist>
<simpara>You can generate the projects list index file using the project_index action
(the <emphasis>TXT</emphasis> link on projects list page) directly from gitweb; see also
"Generating projects list using gitweb" section below.</simpara>
<simpara>Example contents:</simpara>
<screen>foo.git       Joe+R+Hacker+&lt;joe@example.com&gt;
foo/bar.git   O+W+Ner+&lt;owner@example.org&gt;</screen>
<simpara>By default this file controls only which projects are <emphasis role="strong">visible</emphasis> on projects
list page (note that entries that do not point to correctly recognized Git
repositories won't be displayed by gitweb).  Even if a project is not
visible on projects list page, you can view it nevertheless by hand-crafting
a gitweb URL.  By setting <emphasis>$strict_export</emphasis> configuration variable (see
<xref linkend="gitweb.conf(5)" />) to true value you can allow viewing only of
repositories also shown on the overview page (i.e. only projects explicitly
listed in projects list file will be accessible).</simpara>
</section>
<section id="gitweb(1)__generating_projects_list_using_gitweb">
<title>Generating projects list using gitweb</title>
<simpara>We assume that GITWEB_CONFIG has its default Makefile value, namely
<emphasis>gitweb_config.perl</emphasis>. Put the following in <emphasis>gitweb_make_index.perl</emphasis> file:</simpara>
<screen>read_config_file("gitweb_config.perl");
$projects_list = $projectroot;</screen>
<simpara>Then create the following script to get list of project in the format
suitable for GITWEB_LIST build configuration variable (or
<emphasis>$projects_list</emphasis> variable in gitweb config):</simpara>
<screen>#!/bin/sh

export GITWEB_CONFIG="gitweb_make_index.perl"
export GATEWAY_INTERFACE="CGI/1.1"
export HTTP_ACCEPT="*/*"
export REQUEST_METHOD="GET"
export QUERY_STRING="a=project_index"

perl -- /var/www/cgi-bin/gitweb.cgi</screen>
<simpara>Run this script and save its output to a file.  This file could then be used
as projects list file, which means that you can set <emphasis>$projects_list</emphasis> to its
filename.</simpara>
</section>
<section id="gitweb(1)__controlling_access_to_git_repositories">
<title>Controlling access to Git repositories</title>
<simpara>By default all Git repositories under <emphasis>$projectroot</emphasis> are visible and
available to gitweb.  You can however configure how gitweb controls access
to repositories.</simpara>
<itemizedlist>
<listitem>
<simpara>
As described in "Projects list file format" section, you can control which
projects are <emphasis role="strong">visible</emphasis> by selectively including repositories in projects
list file, and setting <emphasis>$projects_list</emphasis> gitweb configuration variable to
point to it.  With <emphasis>$strict_export</emphasis> set, projects list file can be used to
control which repositories are <emphasis role="strong">available</emphasis> as well.
</simpara>
</listitem>
<listitem>
<simpara>
You can configure gitweb to only list and allow viewing of the explicitly
exported repositories, via <emphasis>$export_ok</emphasis> variable in gitweb config file; see
<xref linkend="gitweb.conf(5)" /> manpage.  If it evaluates to true, gitweb shows
repositories only if this file named by <emphasis>$export_ok</emphasis> exists in its object
database (if directory has the magic file named <emphasis>$export_ok</emphasis>).
</simpara>
<simpara>For example <xref linkend="git-daemon(1)" /> by default (unless <emphasis>--export-all</emphasis> option
is used) allows pulling only for those repositories that have
<emphasis>git-daemon-export-ok</emphasis> file.  Adding</simpara>
<screen>our $export_ok = "git-daemon-export-ok";</screen>
<simpara>makes gitweb show and allow access only to those repositories that can be
fetched from via <emphasis>git://</emphasis> protocol.</simpara>
</listitem>
<listitem>
<simpara>
Finally, it is possible to specify an arbitrary perl subroutine that will
be called for each repository to determine if it can be exported.  The
subroutine receives an absolute path to the project (repository) as its only
parameter (i.e. "$projectroot/$project").
</simpara>
<simpara>For example, if you use mod_perl to run the script, and have dumb
HTTP protocol authentication configured for your repositories, you
can use the following hook to allow access only if the user is
authorized to read the files:</simpara>
<screen>$export_auth_hook = sub {
        use Apache2::SubRequest ();
        use Apache2::Const -compile =&gt; qw(HTTP_OK);
        my $path = "$_[0]/HEAD";
        my $r    = Apache2::RequestUtil-&gt;request;
        my $sub  = $r-&gt;lookup_file($path);
        return $sub-&gt;filename eq $path
            &amp;&amp; $sub-&gt;status == Apache2::Const::HTTP_OK;
};</screen>
</listitem>
</itemizedlist>
</section>
<section id="gitweb(1)__per_repository_gitweb_configuration">
<title>Per-repository gitweb configuration</title>
<simpara>You can configure individual repositories shown in gitweb by creating file
in the <emphasis>GIT_DIR</emphasis> of Git repository, or by setting some repo configuration
variable (in <emphasis>GIT_DIR/config</emphasis>, see <xref linkend="git-config(1)" />).</simpara>
<simpara>You can use the following files in repository:</simpara>
<variablelist>
<varlistentry>
<term>
README.html
</term>
<listitem>
<simpara>
        A html file (HTML fragment) which is included on the gitweb project
        "summary" page inside <emphasis>&lt;div&gt;</emphasis> block element. You can use it for longer
        description of a project, to provide links (for example to project's
        homepage), etc. This is recognized only if XSS prevention is off
        (<emphasis>$prevent_xss</emphasis> is false, see <xref linkend="gitweb.conf(5)" />); a way to include
        a README safely when XSS prevention is on may be worked out in the
        future.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
description (or <emphasis>gitweb.description</emphasis>)
</term>
<listitem>
<simpara>
        Short (shortened to <emphasis>$projects_list_description_width</emphasis> in the projects
        list page, which is 25 characters by default; see
        <xref linkend="gitweb.conf(5)" />) single line description of a project (of a
        repository).  Plain text file; HTML will be escaped.  By default set to
</simpara>
<screen>Unnamed repository; edit this file to name it for gitweb.</screen>
<simpara>from the template during repository creation, usually installed in
<emphasis>/usr/share/git-core/templates/</emphasis>.  You can use the <emphasis>gitweb.description</emphasis> repo
configuration variable, but the file takes precedence.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
category (or <emphasis>gitweb.category</emphasis>)
</term>
<listitem>
<simpara>
        Singe line category of a project, used to group projects if
        <emphasis>$projects_list_group_categories</emphasis> is enabled.  By default (file and
        configuration variable absent), uncategorized projects are put in the
        <emphasis>$project_list_default_category</emphasis> category.  You can use the
        <emphasis>gitweb.category</emphasis> repo configuration variable, but the file takes
        precedence.
</simpara>
<simpara>The configuration variables <emphasis>$projects_list_group_categories</emphasis> and
<emphasis>$project_list_default_category</emphasis> are described in <xref linkend="gitweb.conf(5)" /></simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
cloneurl (or multiple-valued <emphasis>gitweb.url</emphasis>)
</term>
<listitem>
<simpara>
        File with repository URL (used for clone and fetch), one per line.
        Displayed in the project summary page. You can use multiple-valued
        <emphasis>gitweb.url</emphasis> repository configuration variable for that, but the file
        takes precedence.
</simpara>
<simpara>This is per-repository enhancement / version of global prefix-based
<emphasis>@git_base_url_list</emphasis> gitweb configuration variable (see
<xref linkend="gitweb.conf(5)" />).</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
gitweb.owner
</term>
<listitem>
<simpara>
        You can use the <emphasis>gitweb.owner</emphasis> repository configuration variable to set
        repository's owner.  It is displayed in the project list and summary
        page.
</simpara>
<simpara>If it's not set, filesystem directory's owner is used (via GECOS field,
i.e. real name field from <emphasis role="strong">getpwuid</emphasis>(3)) if <emphasis>$projects_list</emphasis> is unset
(gitweb scans <emphasis>$projectroot</emphasis> for repositories); if <emphasis>$projects_list</emphasis>
points to file with list of repositories, then project owner defaults to
value from this file for given repository.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
various <emphasis>gitweb.*</emphasis> config variables (in config)
</term>
<listitem>
<simpara>
        Read description of <emphasis>%feature</emphasis> hash for detailed list, and descriptions.
        See also "Configuring gitweb features" section in <xref linkend="gitweb.conf(5)" />
</simpara>
</listitem>
</varlistentry>
</variablelist>
</section>
</simplesect>
<simplesect id="gitweb(1)__actions_and_urls">
<title>ACTIONS, AND URLS</title>
<simpara>Gitweb can use path_info (component) based URLs, or it can pass all necessary
information via query parameters.  The typical gitweb URLs are broken down in to
five components:</simpara>
<screen>.../gitweb.cgi/&lt;repo&gt;/&lt;action&gt;/&lt;revision&gt;:/&lt;path&gt;?&lt;arguments&gt;</screen>
<variablelist>
<varlistentry>
<term>
repo
</term>
<listitem>
<simpara>
        The repository the action will be performed on.
</simpara>
<simpara>All actions except for those that list all available projects,
in whatever form, require this parameter.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
action
</term>
<listitem>
<simpara>
        The action that will be run.  Defaults to <emphasis>projects_list</emphasis> if repo
        is not set, and to <emphasis>summary</emphasis> otherwise.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
revision
</term>
<listitem>
<simpara>
        Revision shown.  Defaults to HEAD.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
path
</term>
<listitem>
<simpara>
        The path within the &lt;repository&gt; that the action is performed on,
        for those actions that require it.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
arguments
</term>
<listitem>
<simpara>
        Any arguments that control the behaviour of the action.
</simpara>
</listitem>
</varlistentry>
</variablelist>
<simpara>Some actions require or allow to specify two revisions, and sometimes even two
pathnames.  In most general form such path_info (component) based gitweb URL
looks like this:</simpara>
<screen>.../gitweb.cgi/&lt;repo&gt;/&lt;action&gt;/&lt;revision-from&gt;:/&lt;path-from&gt;..&lt;revision-to&gt;:/&lt;path-to&gt;?&lt;arguments&gt;</screen>
<simpara>Each action is implemented as a subroutine, and must be present in %actions
hash.  Some actions are disabled by default, and must be turned on via feature
mechanism.  For example to enable <emphasis>blame</emphasis> view add the following to gitweb
configuration file:</simpara>
<screen>$feature{'blame'}{'default'} = [1];</screen>
<section id="gitweb(1)__actions">
<title>Actions:</title>
<simpara>The standard actions are:</simpara>
<variablelist>
<varlistentry>
<term>
project_list
</term>
<listitem>
<simpara>
        Lists the available Git repositories.  This is the default command if no
        repository is specified in the URL.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
summary
</term>
<listitem>
<simpara>
        Displays summary about given repository.  This is the default command if
        no action is specified in URL, and only repository is specified.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
heads
</term>
<term>
remotes
</term>
<listitem>
<simpara>
        Lists all local or all remote-tracking branches in given repository.
</simpara>
<simpara>The latter is not available by default, unless configured.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
tags
</term>
<listitem>
<simpara>
        List all tags (lightweight and annotated) in given repository.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
blob
</term>
<term>
tree
</term>
<listitem>
<simpara>
        Shows the files and directories in a given repository path, at given
        revision.  This is default command if no action is specified in the URL,
        and path is given.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
blob_plain
</term>
<listitem>
<simpara>
        Returns the raw data for the file in given repository, at given path and
        revision.  Links to this action are marked <emphasis>raw</emphasis>.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
blobdiff
</term>
<listitem>
<simpara>
        Shows the difference between two revisions of the same file.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
blame
</term>
<term>
blame_incremental
</term>
<listitem>
<simpara>
        Shows the blame (also called annotation) information for a file. On a
        per line basis it shows the revision in which that line was last changed
        and the user that committed the change.  The incremental version (which
        if configured is used automatically when JavaScript is enabled) uses
        Ajax to incrementally add blame info to the contents of given file.
</simpara>
<simpara>This action is disabled by default for performance reasons.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
commit
</term>
<term>
commitdiff
</term>
<listitem>
<simpara>
        Shows information about a specific commit in a repository.  The <emphasis>commit</emphasis>
        view shows information about commit in more detail, the <emphasis>commitdiff</emphasis>
        action shows changeset for given commit.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
patch
</term>
<listitem>
<simpara>
        Returns the commit in plain text mail format, suitable for applying with
        <xref linkend="git-am(1)" />.
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
tag
</term>
<listitem>
<simpara>
        Display specific annotated tag (tag object).
</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
log
</term>
<term>
shortlog
</term>
<listitem>
<simpara>
        Shows log information (commit message or just commit subject) for a
        given branch (starting from given revision).
</simpara>
<simpara>The <emphasis>shortlog</emphasis> view is more compact; it shows one commit per line.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
history
</term>
<listitem>
<simpara>
        Shows history of the file or directory in a given repository path,
        starting from given revision (defaults to HEAD, i.e. default branch).
</simpara>
<simpara>This view is similar to <emphasis>shortlog</emphasis> view.</simpara>
</listitem>
</varlistentry>
<varlistentry>
<term>
rss
</term>
<term>
atom
</term>
<listitem>
<simpara>
        Generates an RSS (or Atom) feed of changes to repository.
</simpara>
</listitem>
</varlistentry>
</variablelist>
</section>
</simplesect>
<simplesect id="gitweb(1)__webserver_configuration">
<title>WEBSERVER CONFIGURATION</title>
<simpara>This section explains how to configure some common webservers to run gitweb. In
all cases, <emphasis>/path/to/gitweb</emphasis> in the examples is the directory you ran installed
gitweb in, and contains <emphasis>gitweb_config.perl</emphasis>.</simpara>
<simpara>If you've configured a web server that isn't listed here for gitweb, please send
in the instructions so they can be included in a future release.</simpara>
<section id="gitweb(1)__apache_as_cgi">
<title>Apache as CGI</title>
<simpara>Apache must be configured to support CGI scripts in the directory in
which gitweb is installed.  Let's assume that it is <emphasis>/var/www/cgi-bin</emphasis>
directory.</simpara>
<screen>ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

&lt;Directory "/var/www/cgi-bin"&gt;
    Options Indexes FollowSymlinks ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
&lt;/Directory&gt;</screen>
<simpara>With that configuration the full path to browse repositories would be:</simpara>
<literallayout class="monospaced">http://server/cgi-bin/gitweb.cgi</literallayout>
</section>
<section id="gitweb(1)__apache_with_mod_perl_via_modperl_registry">
<title>Apache with mod_perl, via ModPerl::Registry</title>
<simpara>You can use mod_perl with gitweb.  You must install Apache::Registry
(for mod_perl 1.x) or ModPerl::Registry (for mod_perl 2.x) to enable
this support.</simpara>
<simpara>Assuming that gitweb is installed to <emphasis>/var/www/perl</emphasis>, the following
Apache configuration (for mod_perl 2.x) is suitable.</simpara>
<screen>Alias /perl "/var/www/perl"

&lt;Directory "/var/www/perl"&gt;
    SetHandler perl-script
    PerlResponseHandler ModPerl::Registry
    PerlOptions +ParseHeaders
    Options Indexes FollowSymlinks +ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
&lt;/Directory&gt;</screen>
<simpara>With that configuration the full path to browse repositories would be:</simpara>
<literallayout class="monospaced">http://server/perl/gitweb.cgi</literallayout>
</section>
<section id="gitweb(1)__apache_with_fastcgi">
<title>Apache with FastCGI</title>
<simpara>Gitweb works with Apache and FastCGI.  First you need to rename, copy
or symlink gitweb.cgi to gitweb.fcgi.  Let's assume that gitweb is
installed in <emphasis>/usr/share/gitweb</emphasis> directory.  The following Apache
configuration is suitable (UNTESTED!)</simpara>
<screen>FastCgiServer /usr/share/gitweb/gitweb.cgi
ScriptAlias /gitweb /usr/share/gitweb/gitweb.cgi

Alias /gitweb/static /usr/share/gitweb/static
&lt;Directory /usr/share/gitweb/static&gt;
    SetHandler default-handler
&lt;/Directory&gt;</screen>
<simpara>With that configuration the full path to browse repositories would be:</simpara>
<literallayout class="monospaced">http://server/gitweb</literallayout>
</section>
</simplesect>
<simplesect id="gitweb(1)__advanced_web_server_setup">
<title>ADVANCED WEB SERVER SETUP</title>
<simpara>All of those examples use request rewriting, and need <emphasis>mod_rewrite</emphasis>
(or equivalent; examples below are written for Apache).</simpara>
<section id="gitweb(1)__single_url_for_gitweb_and_for_fetching">
<title>Single URL for gitweb and for fetching</title>
<simpara>If you want to have one URL for both gitweb and your <emphasis>http://</emphasis>
repositories, you can configure Apache like this:</simpara>
<screen>&lt;VirtualHost *:80&gt;
    ServerName    git.example.org
    DocumentRoot  /pub/git
    SetEnv        GITWEB_CONFIG   /etc/gitweb.conf

    # turning on mod rewrite
    RewriteEngine on

    # make the front page an internal rewrite to the gitweb script
    RewriteRule ^/$  /cgi-bin/gitweb.cgi

    # make access for "dumb clients" work
    RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ \
                /cgi-bin/gitweb.cgi%{REQUEST_URI}  [L,PT]
&lt;/VirtualHost&gt;</screen>
<simpara>The above configuration expects your public repositories to live under
<emphasis>/pub/git</emphasis> and will serve them as <emphasis>http://git.domain.org/dir-under-pub-git</emphasis>,
both as clonable Git URL and as browsable gitweb interface.  If you then
start your <xref linkend="git-daemon(1)" /> with <emphasis>--base-path=/pub/git --export-all</emphasis>
then you can even use the <emphasis>git://</emphasis> URL with exactly the same path.</simpara>
<simpara>Setting the environment variable <emphasis>GITWEB_CONFIG</emphasis> will tell gitweb to use the
named file (i.e. in this example <emphasis>/etc/gitweb.conf</emphasis>) as a configuration for
gitweb.  You don't really need it in above example; it is required only if
your configuration file is in different place than built-in (during
compiling gitweb) <emphasis>gitweb_config.perl</emphasis> or <emphasis>/etc/gitweb.conf</emphasis>.  See
<xref linkend="gitweb.conf(5)" /> for details, especially information about precedence
rules.</simpara>
<simpara>If you use the rewrite rules from the example you <emphasis role="strong">might</emphasis> also need
something like the following in your gitweb configuration file
(<emphasis>/etc/gitweb.conf</emphasis> following example):</simpara>
<screen>@stylesheets = ("/some/absolute/path/gitweb.css");
$my_uri    = "/";
$home_link = "/";
$per_request_config = 1;</screen>
<simpara>Nowadays though gitweb should create HTML base tag when needed (to set base
URI for relative links), so it should work automatically.</simpara>
</section>
<section id="gitweb(1)__webserver_configuration_with_multiple_projects_root">
<title>Webserver configuration with multiple projects' root</title>
<simpara>If you want to use gitweb with several project roots you can edit your
Apache virtual host and gitweb configuration files in the following way.</simpara>
<simpara>The virtual host configuration (in Apache configuration file) should look
like this:</simpara>
<screen>&lt;VirtualHost *:80&gt;
    ServerName    git.example.org
    DocumentRoot  /pub/git
    SetEnv        GITWEB_CONFIG  /etc/gitweb.conf

    # turning on mod rewrite
    RewriteEngine on

    # make the front page an internal rewrite to the gitweb script
    RewriteRule ^/$  /cgi-bin/gitweb.cgi  [QSA,L,PT]

    # look for a public_git directory in unix users' home
    # http://git.example.org/~&lt;user&gt;/
    RewriteRule ^/\~([^\/]+)(/|/gitweb.cgi)?$   /cgi-bin/gitweb.cgi \
                [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]

    # http://git.example.org/+&lt;user&gt;/
    #RewriteRule ^/\+([^\/]+)(/|/gitweb.cgi)?$  /cgi-bin/gitweb.cgi \
                 [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]

    # http://git.example.org/user/&lt;user&gt;/
    #RewriteRule ^/user/([^\/]+)/(gitweb.cgi)?$ /cgi-bin/gitweb.cgi \
                 [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]

    # defined list of project roots
    RewriteRule ^/scm(/|/gitweb.cgi)?$ /cgi-bin/gitweb.cgi \
                [QSA,E=GITWEB_PROJECTROOT:/pub/scm/,L,PT]
    RewriteRule ^/var(/|/gitweb.cgi)?$ /cgi-bin/gitweb.cgi \
                [QSA,E=GITWEB_PROJECTROOT:/var/git/,L,PT]

    # make access for "dumb clients" work
    RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ \
                /cgi-bin/gitweb.cgi%{REQUEST_URI}  [L,PT]
&lt;/VirtualHost&gt;</screen>
<simpara>Here actual project root is passed to gitweb via <emphasis>GITWEB_PROJECT_ROOT</emphasis>
environment variable from a web server, so you need to put the following
line in gitweb configuration file (<emphasis>/etc/gitweb.conf</emphasis> in above example):</simpara>
<screen>$projectroot = $ENV{'GITWEB_PROJECTROOT'} || "/pub/git";</screen>
<simpara><emphasis role="strong">Note</emphasis> that this requires to be set for each request, so either
<emphasis>$per_request_config</emphasis> must be false, or the above must be put in code
referenced by <emphasis>$per_request_config</emphasis>;</simpara>
<simpara>These configurations enable two things. First, each unix user (<emphasis>&lt;user&gt;</emphasis>) of
the server will be able to browse through gitweb Git repositories found in
<emphasis>~/public_git/</emphasis> with the following url:</simpara>
<literallayout class="monospaced">http://git.example.org/~&lt;user&gt;/</literallayout>
<simpara>If you do not want this feature on your server just remove the second
rewrite rule.</simpara>
<simpara>If you already use mod_userdir` in your virtual host or you don't want to
use the '~ as first character, just comment or remove the second rewrite
rule, and uncomment one of the following according to what you want.</simpara>
<simpara>Second, repositories found in <emphasis>/pub/scm/</emphasis> and <emphasis>/var/git/</emphasis> will be accessible
through <emphasis>http://git.example.org/scm/</emphasis> and <emphasis>http://git.example.org/var/</emphasis>.
You can add as many project roots as you want by adding rewrite rules like
the third and the fourth.</simpara>
</section>
<section id="gitweb(1)__path_info_usage">
<title>PATH_INFO usage</title>
<simpara>If you enable PATH_INFO usage in gitweb by putting</simpara>
<screen>$feature{'pathinfo'}{'default'} = [1];</screen>
<simpara>in your gitweb configuration file, it is possible to set up your server so
that it consumes and produces URLs in the form</simpara>
<literallayout class="monospaced">http://git.example.com/project.git/shortlog/sometag</literallayout>
<simpara>i.e. without <emphasis>gitweb.cgi</emphasis> part, by using a configuration such as the
following.  This configuration assumes that <emphasis>/var/www/gitweb</emphasis> is the
DocumentRoot of your webserver, contains the gitweb.cgi script and
complementary static files (stylesheet, favicon, JavaScript):</simpara>
<screen>&lt;VirtualHost *:80&gt;
        ServerAlias git.example.com

        DocumentRoot /var/www/gitweb

        &lt;Directory /var/www/gitweb&gt;
                Options ExecCGI
                AddHandler cgi-script cgi

                DirectoryIndex gitweb.cgi

                RewriteEngine On
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^.* /gitweb.cgi/$0 [L,PT]
        &lt;/Directory&gt;
&lt;/VirtualHost&gt;</screen>
<simpara>The rewrite rule guarantees that existing static files will be properly
served, whereas any other URL will be passed to gitweb as PATH_INFO
parameter.</simpara>
<simpara><emphasis role="strong">Notice</emphasis> that in this case you don't need special settings for
<emphasis>@stylesheets</emphasis>, <emphasis>$my_uri</emphasis> and <emphasis>$home_link</emphasis>, but you lose "dumb client"
access to your project .git dirs (described in "Single URL for gitweb and
for fetching" section).  A possible workaround for the latter is the
following: in your project root dir (e.g. <emphasis>/pub/git</emphasis>) have the projects
named <emphasis role="strong">without</emphasis> a .git extension (e.g. <emphasis>/pub/git/project</emphasis> instead of
<emphasis>/pub/git/project.git</emphasis>) and configure Apache as follows:</simpara>
<screen>&lt;VirtualHost *:80&gt;
        ServerAlias git.example.com

        DocumentRoot /var/www/gitweb

        AliasMatch ^(/.*?)(\.git)(/.*)?$ /pub/git$1$3
        &lt;Directory /var/www/gitweb&gt;
                Options ExecCGI
                AddHandler cgi-script cgi

                DirectoryIndex gitweb.cgi

                RewriteEngine On
                RewriteCond %{REQUEST_FILENAME} !-f
                RewriteCond %{REQUEST_FILENAME} !-d
                RewriteRule ^.* /gitweb.cgi/$0 [L,PT]
        &lt;/Directory&gt;
&lt;/VirtualHost&gt;</screen>
<simpara>The additional AliasMatch makes it so that</simpara>
<literallayout class="monospaced">http://git.example.com/project.git</literallayout>
<simpara>will give raw access to the project's Git dir (so that the project can be
cloned), while</simpara>
<literallayout class="monospaced">http://git.example.com/project</literallayout>
<simpara>will provide human-friendly gitweb access.</simpara>
<simpara>This solution is not 100% bulletproof, in the sense that if some project has
a named ref (branch, tag) starting with <emphasis>git/</emphasis>, then paths such as</simpara>
<literallayout class="monospaced">http://git.example.com/project/command/abranch..git/abranch</literallayout>
<simpara>will fail with a 404 error.</simpara>
</section>
</simplesect>
<simplesect id="gitweb(1)__bugs">
<title>BUGS</title>
<simpara>Please report any bugs or feature requests to <ulink url="mailto:git@vger.kernel.org">git@vger.kernel.org</ulink>,
putting "gitweb" in the subject of email.</simpara>
</simplesect>
<simplesect id="gitweb(1)__see_also">
<title>SEE ALSO</title>
<simpara><xref linkend="gitweb.conf(5)" />, <xref linkend="git-instaweb(1)" /></simpara>
<simpara><emphasis>gitweb/README</emphasis>, <emphasis>gitweb/INSTALL</emphasis></simpara>
</simplesect>
<simplesect id="gitweb(1)__git">
<title>GIT</title>
<simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
</simplesect>
</sect2>
