Autogenerated manpages for v2.48.1-268-g9520f
[git-manpages.git] / man1 / git-http-backend.1
blob98d9d1765f03dacddba02219441437547778211c
1 '\" t
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/>
5 .\"      Date: 2025-02-06
6 .\"    Manual: Git Manual
7 .\"    Source: Git 2.48.1.268.g9520f7d998
8 .\"  Language: English
9 .\"
10 .TH "GIT\-HTTP\-BACKEND" "1" "2025-02-06" "Git 2\&.48\&.1\&.268\&.g9520f7" "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 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 git-http-backend \- Server side implementation of Git over HTTP
32 .SH "SYNOPSIS"
33 .sp
34 .nf
35 \fIgit http\-backend\fR
36 .fi
37 .SH "DESCRIPTION"
38 .sp
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\&.
40 .sp
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)\&.
42 .sp
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\&.
44 .SH "SERVICES"
45 .sp
46 These services can be enabled/disabled using the per\-repository configuration file:
47 .PP
48 http\&.getanyfile
49 .RS 4
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
51 \fBfalse\fR\&.
52 .RE
53 .PP
54 http\&.uploadpack
55 .RS 4
56 This serves
57 \fIgit fetch\-pack\fR
58 and
59 \fIgit ls\-remote\fR
60 clients\&. It is enabled by default, but a repository can disable it by setting this configuration value to
61 \fBfalse\fR\&.
62 .RE
63 .PP
64 http\&.receivepack
65 .RS 4
66 This serves
67 \fIgit send\-pack\fR
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
70 \fBtrue\fR\&.
71 .RE
72 .SH "URL TRANSLATION"
73 .sp
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\&.
75 .SH "EXAMPLES"
76 .sp
77 All of the following examples map \fBhttp://$hostname/git/foo/bar\&.git\fR to \fB/var/www/git/foo/bar\&.git\fR\&.
78 .PP
79 Apache 2\&.x
80 .RS 4
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:
82 .sp
83 .if n \{\
84 .RS 4
85 .\}
86 .nf
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
103 .if n \{\
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:
109 .if n \{\
110 .RS 4
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/">
118         Order Deny,Allow
119         Deny from env=AUTHREQUIRED
121         AuthType Basic
122         AuthName "Git Access"
123         Require group committers
124         Satisfy Any
125         \&.\&.\&.
126 </LocationMatch>
128 .if n \{\
132 If you do not have
133 \fBmod_rewrite\fR
134 available to match against the query string, it is sufficient to just protect
135 \fBgit\-receive\-pack\fR
136 itself, like:
138 .if n \{\
139 .RS 4
142 <LocationMatch "^/git/\&.*/git\-receive\-pack$">
143         AuthType Basic
144         AuthName "Git Access"
145         Require group committers
146         \&.\&.\&.
147 </LocationMatch>
149 .if n \{\
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
158 \fB403\fR
159 \fBForbidden\fR
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:
164 .if n \{\
165 .RS 4
168 <Location /git/private>
169         AuthType Basic
170         AuthName "Private Git Access"
171         Require group committers
172         \&.\&.\&.
173 </Location>
175 .if n \{\
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:
183 .if n \{\
184 .RS 4
187 ScriptAliasMatch \e
188         "(?x)^/git/(\&.*/(HEAD | \e
189                         info/refs | \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/
198 .if n \{\
202 To serve multiple repositories from different
203 \fBgitnamespaces\fR(7)
204 in a single repository:
206 .if n \{\
207 .RS 4
210 SetEnvIf Request_URI "^/git/([^/]*)" GIT_NAMESPACE=$1
211 ScriptAliasMatch ^/git/[^/]*(\&.*) /usr/libexec/git\-core/git\-http\-backend/storage\&.git$1
213 .if n \{\
218 Accelerated static Apache 2\&.x
219 .RS 4
220 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:
222 .if n \{\
223 .RS 4
226 SetEnv GIT_PROJECT_ROOT /var/www/git
228 AliasMatch ^/git/(\&.*/objects/[0\-9a\-f]{2}/[0\-9a\-f]{38})$          /var/www/git/$1
229 AliasMatch ^/git/(\&.*/objects/pack/pack\-[0\-9a\-f]{40}\&.(pack|idx))$ /var/www/git/$1
230 ScriptAlias /git/ /usr/libexec/git\-core/git\-http\-backend/
232 .if n \{\
236 This can be combined with the gitweb configuration:
238 .if n \{\
239 .RS 4
242 SetEnv GIT_PROJECT_ROOT /var/www/git
244 AliasMatch ^/git/(\&.*/objects/[0\-9a\-f]{2}/[0\-9a\-f]{38})$          /var/www/git/$1
245 AliasMatch ^/git/(\&.*/objects/pack/pack\-[0\-9a\-f]{40}\&.(pack|idx))$ /var/www/git/$1
246 ScriptAliasMatch \e
247         "(?x)^/git/(\&.*/(HEAD | \e
248                         info/refs | \e
249                         objects/info/[^/]+ | \e
250                         git\-(upload|receive)\-pack))$" \e
251         /usr/libexec/git\-core/git\-http\-backend/$1
252 ScriptAlias /git/ /var/www/cgi\-bin/gitweb\&.cgi/
254 .if n \{\
259 Lighttpd
260 .RS 4
261 Ensure that
262 \fBmod_cgi\fR,
263 \fBmod_alias\fR,
264 \fBmod_auth\fR,
265 \fBmod_setenv\fR
266 are loaded, then set
267 \fBGIT_PROJECT_ROOT\fR
268 appropriately and redirect all requests to the CGI:
270 .if n \{\
271 .RS 4
274 alias\&.url += ( "/git" => "/usr/lib/git\-core/git\-http\-backend" )
275 $HTTP["url"] =~ "^/git" {
276         cgi\&.assign = ("" => "")
277         setenv\&.add\-environment = (
278                 "GIT_PROJECT_ROOT" => "/var/www/git",
279                 "GIT_HTTP_EXPORT_ALL" => ""
280         )
283 .if n \{\
287 To enable anonymous read access but authenticated write access:
289 .if n \{\
290 .RS 4
293 $HTTP["querystring"] =~ "service=git\-receive\-pack" {
294         include "git\-auth\&.conf"
296 $HTTP["url"] =~ "^/git/\&.*/git\-receive\-pack$" {
297         include "git\-auth\&.conf"
300 .if n \{\
304 where
305 \fBgit\-auth\&.conf\fR
306 looks something like:
308 .if n \{\
309 .RS 4
312 auth\&.require = (
313         "/" => (
314                 "method" => "basic",
315                 "realm" => "Git Access",
316                 "require" => "valid\-user"
317                )
319 # \&.\&.\&.and set up auth\&.backend here
321 .if n \{\
325 To require authentication for both reads and writes:
327 .if n \{\
328 .RS 4
331 $HTTP["url"] =~ "^/git/private" {
332         include "git\-auth\&.conf"
335 .if n \{\
339 .SH "ENVIRONMENT"
341 \fIgit http\-backend\fR relies upon the \fBCGI\fR environment variables set by the invoking web server, including:
343 .RS 4
344 .ie n \{\
345 \h'-04'\(bu\h'+03'\c
347 .el \{\
348 .sp -1
349 .IP \(bu 2.3
351 PATH_INFO (if GIT_PROJECT_ROOT is set, otherwise PATH_TRANSLATED)
354 .RS 4
355 .ie n \{\
356 \h'-04'\(bu\h'+03'\c
358 .el \{\
359 .sp -1
360 .IP \(bu 2.3
362 REMOTE_USER
365 .RS 4
366 .ie n \{\
367 \h'-04'\(bu\h'+03'\c
369 .el \{\
370 .sp -1
371 .IP \(bu 2.3
373 REMOTE_ADDR
376 .RS 4
377 .ie n \{\
378 \h'-04'\(bu\h'+03'\c
380 .el \{\
381 .sp -1
382 .IP \(bu 2.3
384 CONTENT_TYPE
387 .RS 4
388 .ie n \{\
389 \h'-04'\(bu\h'+03'\c
391 .el \{\
392 .sp -1
393 .IP \(bu 2.3
395 QUERY_STRING
398 .RS 4
399 .ie n \{\
400 \h'-04'\(bu\h'+03'\c
402 .el \{\
403 .sp -1
404 .IP \(bu 2.3
406 REQUEST_METHOD
409 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\&.
411 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\&.
413 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)\&.
415 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\&.
417 All \fBCGI\fR environment variables are available to each of the hooks invoked by the \fIgit\-receive\-pack\fR\&.
418 .SH "GIT"
420 Part of the \fBgit\fR(1) suite