gitweb / READMEon commit gitweb: Add gitweb.conf(5) manpage for gitweb configuration files (6d3902b)
   1GIT web Interface
   2=================
   3
   4The one working on:
   5  http://git.kernel.org/
   6
   7From the git version 1.4.0 gitweb is bundled with git.
   8
   9
  10Runtime gitweb configuration
  11----------------------------
  12
  13Gitweb obtains configuration data from the following sources in the
  14following order:
  15
  161. built-in values (some set during build stage),
  172. common system-wide configuration file (`GITWEB_CONFIG_COMMON`,
  18   defaults to '/etc/gitweb-common.conf'),
  193. either per-instance configuration file (`GITWEB_CONFIG`, defaults to
  20   'gitweb_config.perl' in the same directory as the installed gitweb),
  21   or if it does not exists then system-wide configuration file
  22   (`GITWEB_CONFIG_SYSTEM`, defaults to '/etc/gitweb.conf').
  23
  24Values obtained in later configuration files override values obtained earlier
  25in above sequence.
  26
  27You can read defaults in system-wide GITWEB_CONFIG_SYSTEM from GITWEB_CONFIG
  28by adding
  29
  30  read_config_file($GITWEB_CONFIG_SYSTEM);
  31
  32at very beginning of per-instance GITWEB_CONFIG file.  In this case
  33settings in said per-instance file will override settings from
  34system-wide configuration file.  Note that read_config_file checks
  35itself that the $GITWEB_CONFIG_SYSTEM file exists.
  36
  37The most notable thing that is not configurable at compile time are the
  38optional features, stored in the '%features' variable.
  39
  40Ultimate description on how to reconfigure the default features setting
  41in your `GITWEB_CONFIG` or per-project in `project.git/config` can be found
  42as comments inside 'gitweb.cgi'.
  43
  44See also gitweb.conf(5) manpage.
  45
  46
  47Projects list file format
  48~~~~~~~~~~~~~~~~~~~~~~~~~
  49
  50Instead of having gitweb find repositories by scanning filesystem starting
  51from $projectroot (or $projects_list, if it points to directory), you can
  52provide list of projects by setting $projects_list to a text file with list
  53of projects (and some additional info).  This file uses the following
  54format:
  55
  56One record (for project / repository) per line, whitespace separated fields;
  57does not support (at least for now) lines continuation (newline escaping).
  58Leading and trailing whitespace are ignored, any run of whitespace can be
  59used as field separator (rules for Perl's "split(' ', $line)").  Keyed by
  60the first field, which is project name, i.e. path to repository GIT_DIR
  61relative to $projectroot.  Fields use modified URI encoding, defined in
  62RFC 3986, section 2.1 (Percent-Encoding), or rather "Query string encoding"
  63(see http://en.wikipedia.org/wiki/Query_string#URL_encoding), the difference
  64being that SP (' ') can be encoded as '+' (and therefore '+' has to be also
  65percent-encoded).  Reserved characters are: '%' (used for encoding), '+'
  66(can be used to encode SPACE), all whitespace characters as defined in Perl,
  67including SP, TAB and LF, (used to separate fields in a record).
  68
  69Currently list of fields is
  70 * <repository path>  - path to repository GIT_DIR, relative to $projectroot
  71 * <repository owner> - displayed as repository owner, preferably full name,
  72                        or email, or both
  73
  74You can additionally use $projects_list file to limit which repositories
  75are visible, and together with $strict_export to limit access to
  76repositories (see "Gitweb repositories" section in gitweb/INSTALL).
  77
  78
  79Per-repository gitweb configuration
  80~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81
  82You can also configure individual repositories shown in gitweb by creating
  83file in the GIT_DIR of git repository, or by setting some repo configuration
  84variable (in GIT_DIR/config).
  85
  86You can use the following files in repository:
  87 * README.html
  88   A .html file (HTML fragment) which is included on the gitweb project
  89   summary page inside <div> block element. You can use it for longer
  90   description of a project, to provide links (for example to project's
  91   homepage), etc. This is recognized only if XSS prevention is off
  92   ($prevent_xss is false); a way to include a readme safely when XSS
  93   prevention is on may be worked out in the future.
  94 * description (or gitweb.description)
  95   Short (shortened by default to 25 characters in the projects list page)
  96   single line description of a project (of a repository). Plain text file;
  97   HTML will be escaped. By default set to
  98     Unnamed repository; edit this file to name it for gitweb.
  99   from the template during repository creation. You can use the
 100   gitweb.description repo configuration variable, but the file takes
 101   precedence.
 102 * category (or gitweb.category)
 103   Singe line category of a project, used to group projects if
 104   $projects_list_group_categories is enabled. By default (file and
 105   configuration variable absent), uncategorized projects are put in
 106   the $project_list_default_category category. You can use the
 107   gitweb.category repo configuration variable, but the file takes
 108   precedence.
 109 * cloneurl (or multiple-valued gitweb.url)
 110   File with repository URL (used for clone and fetch), one per line.
 111   Displayed in the project summary page. You can use multiple-valued
 112   gitweb.url repository configuration variable for that, but the file
 113   takes precedence.
 114 * gitweb.owner
 115   You can use the gitweb.owner repository configuration variable to set
 116   repository's owner. It is displayed in the project list and summary
 117   page. If it's not set, filesystem directory's owner is used
 118   (via GECOS field / real name field from getpwiud(3)).
 119 * various gitweb.* config variables (in config)
 120   Read description of %feature hash for detailed list, and some
 121   descriptions.
 122
 123
 124Webserver configuration
 125-----------------------
 126
 127If you want to have one URL for both gitweb and your http://
 128repositories, you can configure apache like this:
 129
 130<VirtualHost *:80>
 131    ServerName          git.example.org
 132    DocumentRoot        /pub/git
 133    SetEnv                      GITWEB_CONFIG   /etc/gitweb.conf
 134
 135    # turning on mod rewrite
 136    RewriteEngine on
 137
 138    # make the front page an internal rewrite to the gitweb script
 139    RewriteRule ^/$  /cgi-bin/gitweb.cgi
 140
 141    # make access for "dumb clients" work
 142    RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI}  [L,PT]
 143</VirtualHost>
 144
 145The above configuration expects your public repositories to live under
 146/pub/git and will serve them as http://git.domain.org/dir-under-pub-git,
 147both as cloneable GIT URL and as browseable gitweb interface.
 148If you then start your git-daemon with --base-path=/pub/git --export-all
 149then you can even use the git:// URL with exactly the same path.
 150
 151Setting the environment variable GITWEB_CONFIG will tell gitweb to use
 152the named file (i.e. in this example /etc/gitweb.conf) as a
 153configuration for gitweb.  Perl variables defined in here will
 154override the defaults given at the head of the gitweb.perl (or
 155gitweb.cgi).  Look at the comments in that file for information on
 156which variables and what they mean.
 157
 158If you use the rewrite rules from the example you'll likely also need
 159something like the following in your gitweb.conf (or gitweb_config.perl) file:
 160
 161  @stylesheets = ("/some/absolute/path/gitweb.css");
 162  $my_uri = "/";
 163  $home_link = "/";
 164
 165
 166Webserver configuration with multiple projects' root
 167----------------------------------------------------
 168
 169If you want to use gitweb with several project roots you can edit your apache
 170virtual host and gitweb.conf configuration files like this :
 171
 172virtual host configuration :
 173
 174<VirtualHost *:80>
 175    ServerName                  git.example.org
 176    DocumentRoot                /pub/git
 177    SetEnv                              GITWEB_CONFIG   /etc/gitweb.conf
 178
 179    # turning on mod rewrite
 180    RewriteEngine on
 181
 182    # make the front page an internal rewrite to the gitweb script
 183    RewriteRule ^/$             /cgi-bin/gitweb.cgi [QSA,L,PT]
 184
 185    # look for a public_git folder in unix users' home
 186    # http://git.example.org/~<user>/
 187    RewriteRule ^/\~([^\/]+)(/|/gitweb.cgi)?$   /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]
 188
 189    # http://git.example.org/+<user>/
 190    #RewriteRule ^/\+([^\/]+)(/|/gitweb.cgi)?$  /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]
 191
 192    # http://git.example.org/user/<user>/
 193    #RewriteRule ^/user/([^\/]+)/(gitweb.cgi)?$ /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/home/$1/public_git/,L,PT]
 194
 195    # defined list of project roots
 196    RewriteRule ^/scm(/|/gitweb.cgi)?$          /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/pub/scm/,L,PT]
 197    RewriteRule ^/var(/|/gitweb.cgi)?$          /cgi-bin/gitweb.cgi [QSA,E=GITWEB_PROJECTROOT:/var/git/,L,PT]
 198
 199    # make access for "dumb clients" work
 200    RewriteRule ^/(.*\.git/(?!/?(HEAD|info|objects|refs)).*)?$ /cgi-bin/gitweb.cgi%{REQUEST_URI}  [L,PT]
 201</VirtualHost>
 202
 203gitweb.conf configuration :
 204
 205$projectroot = $ENV{'GITWEB_PROJECTROOT'} || "/pub/git";
 206
 207These configurations enable two things. First, each unix user (<user>) of the
 208server will be able to browse through gitweb git repositories found in
 209~/public_git/ with the following url : http://git.example.org/~<user>/
 210
 211If you do not want this feature on your server just remove the second rewrite rule.
 212
 213If you already use mod_userdir in your virtual host or you don't want to use
 214the '~' as first character just comment or remove the second rewrite rule and
 215uncomment one of the following according to what you want.
 216
 217Second, repositories found in /pub/scm/ and /var/git/ will be accesible
 218through http://git.example.org/scm/ and http://git.example.org/var/.
 219You can add as many project roots as you want by adding rewrite rules like the
 220third and the fourth.
 221
 222
 223PATH_INFO usage
 224-----------------------
 225If you enable PATH_INFO usage in gitweb by putting
 226
 227   $feature{'pathinfo'}{'default'} = [1];
 228
 229in your gitweb.conf, it is possible to set up your server so that it
 230consumes and produces URLs in the form
 231
 232http://git.example.com/project.git/shortlog/sometag
 233
 234by using a configuration such as the following, that assumes that
 235/var/www/gitweb is the DocumentRoot of your webserver, and that it
 236contains the gitweb.cgi script and complementary static files
 237(stylesheet, favicon):
 238
 239<VirtualHost *:80>
 240        ServerAlias git.example.com
 241
 242        DocumentRoot /var/www/gitweb
 243
 244        <Directory /var/www/gitweb>
 245                Options ExecCGI
 246                AddHandler cgi-script cgi
 247
 248                DirectoryIndex gitweb.cgi
 249
 250                RewriteEngine On
 251                RewriteCond %{REQUEST_FILENAME} !-f
 252                RewriteCond %{REQUEST_FILENAME} !-d
 253                RewriteRule ^.* /gitweb.cgi/$0 [L,PT]
 254        </Directory>
 255</VirtualHost>
 256
 257The rewrite rule guarantees that existing static files will be properly
 258served, whereas any other URL will be passed to gitweb as PATH_INFO
 259parameter.
 260
 261Notice that in this case you don't need special settings for
 262@stylesheets, $my_uri and $home_link, but you lose "dumb client" access
 263to your project .git dirs. A possible workaround for the latter is the
 264following: in your project root dir (e.g. /pub/git) have the projects
 265named without a .git extension (e.g. /pub/git/project instead of
 266/pub/git/project.git) and configure Apache as follows:
 267
 268<VirtualHost *:80>
 269        ServerAlias git.example.com
 270
 271        DocumentRoot /var/www/gitweb
 272
 273        AliasMatch ^(/.*?)(\.git)(/.*)?$ /pub/git$1$3
 274        <Directory /var/www/gitweb>
 275                Options ExecCGI
 276                AddHandler cgi-script cgi
 277
 278                DirectoryIndex gitweb.cgi
 279
 280                RewriteEngine On
 281                RewriteCond %{REQUEST_FILENAME} !-f
 282                RewriteCond %{REQUEST_FILENAME} !-d
 283                RewriteRule ^.* /gitweb.cgi/$0 [L,PT]
 284        </Directory>
 285</VirtualHost>
 286
 287The additional AliasMatch makes it so that
 288
 289http://git.example.com/project.git
 290
 291will give raw access to the project's git dir (so that the project can
 292be cloned), while
 293
 294http://git.example.com/project
 295
 296will provide human-friendly gitweb access.
 297
 298This solution is not 100% bulletproof, in the sense that if some project
 299has a named ref (branch, tag) starting with 'git/', then paths such as
 300
 301http://git.example.com/project/command/abranch..git/abranch
 302
 303will fail with a 404 error.
 304
 305
 306
 307Originally written by:
 308  Kay Sievers <kay.sievers@vrfy.org>
 309
 310Any comment/question/concern to:
 311  Git mailing list <git@vger.kernel.org>