2 .\" Title: git-http-backend
3 .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author]
4 .\" Generator: DocBook XSL Stylesheets v1.79.2 <http://docbook.sf.net/>
7 .\" Source: Git 2.47.0.rc1.33.g90fe3800b9
10 .TH "GIT\-HTTP\-BACKEND" "1" "2024-10-04" "Git 2\&.47\&.0\&.rc1\&.33\&.g9" "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
39 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\&.
41 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 environment variable is set)\&.
43 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\&.
46 These services can be enabled/disabled using the per\-repository configuration file:
50 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 value to
60 clients\&. It is enabled by default, but a repository can disable it by setting this configuration value to
68 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
69 \fBfalse\fR, or enabled for all users, including anonymous users, by setting it to
74 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\&.
77 All of the following examples map \fBhttp://$hostname/git/foo/bar\&.git\fR to \fB/var/www/git/foo/bar\&.git\fR\&.
81 Ensure mod_cgi, mod_alias, and mod_env are enabled, set GIT_PROJECT_ROOT (or DocumentRoot) appropriately, and create a ScriptAlias to the CGI:
87 SetEnv GIT_PROJECT_ROOT /var/www/git
88 SetEnv GIT_HTTP_EXPORT_ALL
89 ScriptAlias /git/ /usr/libexec/git\-core/git\-http\-backend/
91 # This is not strictly necessary using Apache and a modern version of
92 # git\-http\-backend, as the webserver will pass along the header in the
93 # environment as HTTP_GIT_PROTOCOL, and http\-backend will copy that into
94 # GIT_PROTOCOL\&. But you may need this line (or something similar if you
95 # are using a different webserver), or if you want to support older Git
96 # versions that did not do that copying\&.
98 # Having the webserver set up GIT_PROTOCOL is perfectly fine even with
99 # modern versions (and will take precedence over HTTP_GIT_PROTOCOL,
100 # which means it can be used to override the client\*(Aqs request)\&.
101 SetEnvIf Git\-Protocol "\&.*" GIT_PROTOCOL=$0
107 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:
113 RewriteCond %{QUERY_STRING} service=git\-receive\-pack [OR]
114 RewriteCond %{REQUEST_URI} /git\-receive\-pack$
115 RewriteRule ^/git/ \- [E=AUTHREQUIRED:yes]
117 <LocationMatch "^/git/">
119 Deny from env=AUTHREQUIRED
122 AuthName "Git Access"
123 Require group committers
134 available to match against the query string, it is sufficient to just protect
135 \fBgit\-receive\-pack\fR
142 <LocationMatch "^/git/\&.*/git\-receive\-pack$">
144 AuthName "Git Access"
145 Require group committers
153 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
154 \fBhttp\&.receivepack\fR
155 config option in any repositories that should accept a push\&. The default behavior, if
156 \fBhttp\&.receivepack\fR
157 is not set, is to reject any pushes by unauthenticated users; the initial request will therefore report
159 to the client, without even giving an opportunity for authentication\&.
161 To require authentication for both reads and writes, use a Location directive around the repository, or one of its parent directories:
167 <Location /git/private>
169 AuthName "Private Git Access"
170 Require group committers
178 To serve gitweb at the same url, use a ScriptAliasMatch to only those URLs that
179 \fIgit http\-backend\fR
180 can handle, and forward the rest to gitweb:
187 "(?x)^/git/(\&.*/(HEAD | \e
189 objects/(info/[^/]+ | \e
190 [0\-9a\-f]{2}/[0\-9a\-f]{38} | \e
191 pack/pack\-[0\-9a\-f]{40}\e\&.(pack|idx)) | \e
192 git\-(upload|receive)\-pack))$" \e
193 /usr/libexec/git\-core/git\-http\-backend/$1
195 ScriptAlias /git/ /var/www/cgi\-bin/gitweb\&.cgi/
201 To serve multiple repositories from different
202 \fBgitnamespaces\fR(7)
203 in a single repository:
209 SetEnvIf Request_URI "^/git/([^/]*)" GIT_NAMESPACE=$1
210 ScriptAliasMatch ^/git/[^/]*(\&.*) /usr/libexec/git\-core/git\-http\-backend/storage\&.git$1
217 Accelerated static Apache 2\&.x
219 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:
225 SetEnv GIT_PROJECT_ROOT /var/www/git
227 AliasMatch ^/git/(\&.*/objects/[0\-9a\-f]{2}/[0\-9a\-f]{38})$ /var/www/git/$1
228 AliasMatch ^/git/(\&.*/objects/pack/pack\-[0\-9a\-f]{40}\&.(pack|idx))$ /var/www/git/$1
229 ScriptAlias /git/ /usr/libexec/git\-core/git\-http\-backend/
235 This can be combined with the gitweb configuration:
241 SetEnv GIT_PROJECT_ROOT /var/www/git
243 AliasMatch ^/git/(\&.*/objects/[0\-9a\-f]{2}/[0\-9a\-f]{38})$ /var/www/git/$1
244 AliasMatch ^/git/(\&.*/objects/pack/pack\-[0\-9a\-f]{40}\&.(pack|idx))$ /var/www/git/$1
246 "(?x)^/git/(\&.*/(HEAD | \e
248 objects/info/[^/]+ | \e
249 git\-(upload|receive)\-pack))$" \e
250 /usr/libexec/git\-core/git\-http\-backend/$1
251 ScriptAlias /git/ /var/www/cgi\-bin/gitweb\&.cgi/
266 \fBGIT_PROJECT_ROOT\fR
267 appropriately and redirect all requests to the CGI:
273 alias\&.url += ( "/git" => "/usr/lib/git\-core/git\-http\-backend" )
274 $HTTP["url"] =~ "^/git" {
275 cgi\&.assign = ("" => "")
276 setenv\&.add\-environment = (
277 "GIT_PROJECT_ROOT" => "/var/www/git",
278 "GIT_HTTP_EXPORT_ALL" => ""
286 To enable anonymous read access but authenticated write access:
292 $HTTP["querystring"] =~ "service=git\-receive\-pack" {
293 include "git\-auth\&.conf"
295 $HTTP["url"] =~ "^/git/\&.*/git\-receive\-pack$" {
296 include "git\-auth\&.conf"
304 \fBgit\-auth\&.conf\fR
305 looks something like:
314 "realm" => "Git Access",
315 "require" => "valid\-user"
318 # \&.\&.\&.and set up auth\&.backend here
324 To require authentication for both reads and writes:
330 $HTTP["url"] =~ "^/git/private" {
331 include "git\-auth\&.conf"
340 \fIgit http\-backend\fR relies upon the \fBCGI\fR environment variables set by the invoking web server, including:
350 PATH_INFO (if GIT_PROJECT_ROOT is set, otherwise PATH_TRANSLATED)
408 The \fBGIT_HTTP_EXPORT_ALL\fR environment 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\&.
410 The \fBGIT_HTTP_MAX_REQUEST_BUFFER\fR environment variable (or the \fBhttp\&.maxRequestBuffer\fR config option) 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\&.
412 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)\&.
414 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\&.
416 All \fBCGI\fR environment variables are available to each of the hooks invoked by the \fIgit\-receive\-pack\fR\&.
419 Part of the \fBgit\fR(1) suite