2 .\" Title: git-http-backend
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
7 .\" Source: Git 2.42.0.rc1.11.gfc6bba66bc
10 .TH "GIT\-HTTP\-BACKEND" "1" "2023\-08\-14" "Git 2\&.42\&.0\&.rc1\&.11\&.gf" "Git Manual"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
25 .\" disable justification (adjust text to left margin only)
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
31 git-http-backend \- Server side implementation of Git over HTTP
35 \fIgit http\-backend\fR
40 A simple CGI program to serve the contents of a Git repository to Git clients accessing the repository over http:// and https:// protocols\&. The program supports clients fetching using both the smart HTTP protocol and the backwards\-compatible dumb HTTP protocol, as well as clients pushing using the smart HTTP protocol\&. It also supports Git\(cqs more\-efficient "v2" protocol if properly configured; see the discussion of \fBGIT_PROTOCOL\fR in the ENVIRONMENT section below\&.
42 It verifies that the directory has the magic file "git\-daemon\-export\-ok", and it will refuse to export any Git directory that hasn\(cqt explicitly been marked for export this way (unless the \fBGIT_HTTP_EXPORT_ALL\fR environmental variable is set)\&.
44 By default, only the \fBupload\-pack\fR service is enabled, which serves \fIgit fetch\-pack\fR and \fIgit ls\-remote\fR clients, which are invoked from \fIgit fetch\fR, \fIgit pull\fR, and \fIgit clone\fR\&. If the client is authenticated, the \fBreceive\-pack\fR service is enabled, which serves \fIgit send\-pack\fR clients, which is invoked from \fIgit push\fR\&.
47 These services can be enabled/disabled using the per\-repository configuration file:
51 This serves Git clients older than version 1\&.6\&.6 that are unable to use the upload pack service\&. When enabled, clients are able to read any file within the repository, including objects that are no longer reachable from a branch but are still present\&. It is enabled by default, but a repository can disable it by setting this configuration item to
61 clients\&. It is enabled by default, but a repository can disable it by setting this configuration item to
69 clients, allowing push\&. It is disabled by default for anonymous users, and enabled by default for users authenticated by the web server\&. It can be disabled by setting this item to
70 \fBfalse\fR, or enabled for all users, including anonymous users, by setting it to
75 To determine the location of the repository on disk, \fIgit http\-backend\fR concatenates the environment variables PATH_INFO, which is set automatically by the web server, and GIT_PROJECT_ROOT, which must be set manually in the web server configuration\&. If GIT_PROJECT_ROOT is not set, \fIgit http\-backend\fR reads PATH_TRANSLATED, which is also set automatically by the web server\&.
78 All of the following examples map \fBhttp://$hostname/git/foo/bar\&.git\fR to \fB/var/www/git/foo/bar\&.git\fR\&.
82 Ensure mod_cgi, mod_alias, and mod_env are enabled, set GIT_PROJECT_ROOT (or DocumentRoot) appropriately, and create a ScriptAlias to the CGI:
88 SetEnv GIT_PROJECT_ROOT /var/www/git
89 SetEnv GIT_HTTP_EXPORT_ALL
90 ScriptAlias /git/ /usr/libexec/git\-core/git\-http\-backend/
92 # This is not strictly necessary using Apache and a modern version of
93 # git\-http\-backend, as the webserver will pass along the header in the
94 # environment as HTTP_GIT_PROTOCOL, and http\-backend will copy that into
95 # GIT_PROTOCOL\&. But you may need this line (or something similar if you
96 # are using a different webserver), or if you want to support older Git
97 # versions that did not do that copying\&.
99 # Having the webserver set up GIT_PROTOCOL is perfectly fine even with
100 # modern versions (and will take precedence over HTTP_GIT_PROTOCOL,
101 # which means it can be used to override the client\*(Aqs request)\&.
102 SetEnvIf Git\-Protocol "\&.*" GIT_PROTOCOL=$0
108 To enable anonymous read access but authenticated write access, require authorization for both the initial ref advertisement (which we detect as a push via the service parameter in the query string), and the receive\-pack invocation itself:
114 RewriteCond %{QUERY_STRING} service=git\-receive\-pack [OR]
115 RewriteCond %{REQUEST_URI} /git\-receive\-pack$
116 RewriteRule ^/git/ \- [E=AUTHREQUIRED:yes]
118 <LocationMatch "^/git/">
120 Deny from env=AUTHREQUIRED
123 AuthName "Git Access"
124 Require group committers
135 available to match against the query string, it is sufficient to just protect
136 \fBgit\-receive\-pack\fR
143 <LocationMatch "^/git/\&.*/git\-receive\-pack$">
145 AuthName "Git Access"
146 Require group committers
154 In this mode, the server will not request authentication until the client actually starts the object negotiation phase of the push, rather than during the initial contact\&. For this reason, you must also enable the
155 \fBhttp\&.receivepack\fR
156 config option in any repositories that should accept a push\&. The default behavior, if
157 \fBhttp\&.receivepack\fR
158 is not set, is to reject any pushes by unauthenticated users; the initial request will therefore report
160 to the client, without even giving an opportunity for authentication\&.
162 To require authentication for both reads and writes, use a Location directive around the repository, or one of its parent directories:
168 <Location /git/private>
170 AuthName "Private Git Access"
171 Require group committers
179 To serve gitweb at the same url, use a ScriptAliasMatch to only those URLs that
180 \fIgit http\-backend\fR
181 can handle, and forward the rest to gitweb:
188 "(?x)^/git/(\&.*/(HEAD | \e
190 objects/(info/[^/]+ | \e
191 [0\-9a\-f]{2}/[0\-9a\-f]{38} | \e
192 pack/pack\-[0\-9a\-f]{40}\e\&.(pack|idx)) | \e
193 git\-(upload|receive)\-pack))$" \e
194 /usr/libexec/git\-core/git\-http\-backend/$1
196 ScriptAlias /git/ /var/www/cgi\-bin/gitweb\&.cgi/
202 To serve multiple repositories from different
203 \fBgitnamespaces\fR(7)
204 in a single repository:
210 SetEnvIf Request_URI "^/git/([^/]*)" GIT_NAMESPACE=$1
211 ScriptAliasMatch ^/git/[^/]*(\&.*) /usr/libexec/git\-core/git\-http\-backend/storage\&.git$1
219 Accelerated static Apache 2\&.x
221 Similar to the above, but Apache can be used to return static files that are stored on disk\&. On many systems this may be more efficient as Apache can ask the kernel to copy the file contents from the file system directly to the network:
227 SetEnv GIT_PROJECT_ROOT /var/www/git
229 AliasMatch ^/git/(\&.*/objects/[0\-9a\-f]{2}/[0\-9a\-f]{38})$ /var/www/git/$1
230 AliasMatch ^/git/(\&.*/objects/pack/pack\-[0\-9a\-f]{40}\&.(pack|idx))$ /var/www/git/$1
231 ScriptAlias /git/ /usr/libexec/git\-core/git\-http\-backend/
237 This can be combined with the gitweb configuration:
243 SetEnv GIT_PROJECT_ROOT /var/www/git
245 AliasMatch ^/git/(\&.*/objects/[0\-9a\-f]{2}/[0\-9a\-f]{38})$ /var/www/git/$1
246 AliasMatch ^/git/(\&.*/objects/pack/pack\-[0\-9a\-f]{40}\&.(pack|idx))$ /var/www/git/$1
248 "(?x)^/git/(\&.*/(HEAD | \e
250 objects/info/[^/]+ | \e
251 git\-(upload|receive)\-pack))$" \e
252 /usr/libexec/git\-core/git\-http\-backend/$1
253 ScriptAlias /git/ /var/www/cgi\-bin/gitweb\&.cgi/
269 \fBGIT_PROJECT_ROOT\fR
270 appropriately and redirect all requests to the CGI:
276 alias\&.url += ( "/git" => "/usr/lib/git\-core/git\-http\-backend" )
277 $HTTP["url"] =~ "^/git" {
278 cgi\&.assign = ("" => "")
279 setenv\&.add\-environment = (
280 "GIT_PROJECT_ROOT" => "/var/www/git",
281 "GIT_HTTP_EXPORT_ALL" => ""
289 To enable anonymous read access but authenticated write access:
295 $HTTP["querystring"] =~ "service=git\-receive\-pack" {
296 include "git\-auth\&.conf"
298 $HTTP["url"] =~ "^/git/\&.*/git\-receive\-pack$" {
299 include "git\-auth\&.conf"
307 \fBgit\-auth\&.conf\fR
308 looks something like:
317 "realm" => "Git Access",
318 "require" => "valid\-user"
321 # \&.\&.\&.and set up auth\&.backend here
327 To require authentication for both reads and writes:
333 $HTTP["url"] =~ "^/git/private" {
334 include "git\-auth\&.conf"
344 \fIgit http\-backend\fR relies upon the \fBCGI\fR environment variables set by the invoking web server, including:
354 PATH_INFO (if GIT_PROJECT_ROOT is set, otherwise PATH_TRANSLATED)
412 The \fBGIT_HTTP_EXPORT_ALL\fR environmental variable may be passed to \fIgit\-http\-backend\fR to bypass the check for the "git\-daemon\-export\-ok" file in each repository before allowing export of that repository\&.
414 The \fBGIT_HTTP_MAX_REQUEST_BUFFER\fR environment variable (or the \fBhttp\&.maxRequestBuffer\fR config variable) may be set to change the largest ref negotiation request that git will handle during a fetch; any fetch requiring a larger buffer will not succeed\&. This value should not normally need to be changed, but may be helpful if you are fetching from a repository with an extremely large number of refs\&. The value can be specified with a unit (e\&.g\&., \fB100M\fR for 100 megabytes)\&. The default is 10 megabytes\&.
416 Clients may probe for optional protocol capabilities (like the v2 protocol) using the \fBGit\-Protocol\fR HTTP header\&. In order to support these, the contents of that header must appear in the \fBGIT_PROTOCOL\fR environment variable\&. Most webservers will pass this header to the CGI via the \fBHTTP_GIT_PROTOCOL\fR variable, and \fBgit\-http\-backend\fR will automatically copy that to \fBGIT_PROTOCOL\fR\&. However, some webservers may be more selective about which headers they\(cqll pass, in which case they need to be configured explicitly (see the mention of \fBGit\-Protocol\fR in the Apache config from the earlier EXAMPLES section)\&.
418 The backend process sets GIT_COMMITTER_NAME to \fI$REMOTE_USER\fR and GIT_COMMITTER_EMAIL to \fI${REMOTE_USER}@http\&.${REMOTE_ADDR}\fR, ensuring that any reflogs created by \fIgit\-receive\-pack\fR contain some identifying information of the remote user who performed the push\&.
420 All \fBCGI\fR environment variables are available to each of the hooks invoked by the \fIgit\-receive\-pack\fR\&.
423 Part of the \fBgit\fR(1) suite