interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / Documentation / git-http-backend.adoc

307 lines · 11691 bytes Raw Blame History
1git-http-backend(1)
2===================
3
4NAME
5----
6git-http-backend - Server side implementation of Git over HTTP
7
8SYNOPSIS
9--------
10[verse]
11'git http-backend'
12
13DESCRIPTION
14-----------
15A simple CGI program to serve the contents of a Git repository to Git
16clients accessing the repository over http:// and https:// protocols.
17The program supports clients fetching using both the smart HTTP protocol
18and the backwards-compatible dumb HTTP protocol, as well as clients
19pushing using the smart HTTP protocol. It also supports Git's
20more-efficient "v2" protocol if properly configured; see the
21discussion of `GIT_PROTOCOL` in the <<ENVIRONMENT,ENVIRONMENT>> section below.
22
23It verifies that the directory has the magic file
24"git-daemon-export-ok", and it will refuse to export any Git directory
25that hasn't explicitly been marked for export this way (unless the
26`GIT_HTTP_EXPORT_ALL` environment variable is set).
27
28By default, only the `upload-pack` service is enabled, which serves
29'git fetch-pack' and 'git ls-remote' clients, which are invoked from
30'git fetch', 'git pull', and 'git clone'. If the client is authenticated,
31the `receive-pack` service is enabled, which serves 'git send-pack'
32clients, which is invoked from 'git push'.
33
34SERVICES
35--------
36These services can be enabled/disabled using the per-repository
37configuration file:
38
39http.getanyfile::
40 This serves Git clients older than version 1.6.6 that are unable to use the
41 upload pack service. When enabled, clients are able to read
42 any file within the repository, including objects that are
43 no longer reachable from a branch but are still present.
44 It is enabled by default, but a repository can disable it
45 by setting this configuration value to `false`.
46
47http.uploadpack::
48 This serves 'git fetch-pack' and 'git ls-remote' clients.
49 It is enabled by default, but a repository can disable it
50 by setting this configuration value to `false`.
51
52http.receivepack::
53 This serves 'git send-pack' clients, allowing push. It is
54 disabled by default for anonymous users, and enabled by
55 default for users authenticated by the web server. It can be
56 disabled by setting this item to `false`, or enabled for all
57 users, including anonymous users, by setting it to `true`.
58
59http.uploadarchive::
60 This serves 'git archive' clients for remote archive over HTTP/HTTPS
61 protocols. It is disabled by default. It only works in protocol v2.
62
63URL TRANSLATION
64---------------
65To determine the location of the repository on disk, 'git http-backend'
66concatenates the environment variables PATH_INFO, which is set
67automatically by the web server, and GIT_PROJECT_ROOT, which must be set
68manually in the web server configuration. If GIT_PROJECT_ROOT is not
69set, 'git http-backend' reads PATH_TRANSLATED, which is also set
70automatically by the web server.
71
72[[EXAMPLES]]
73EXAMPLES
74--------
75All of the following examples map `http://$hostname/git/foo/bar.git`
76to `/var/www/git/foo/bar.git`.
77
78Apache 2.x::
79 Ensure mod_cgi, mod_alias, and mod_env are enabled, set
80 GIT_PROJECT_ROOT (or DocumentRoot) appropriately, and
81 create a ScriptAlias to the CGI:
82+
83----------------------------------------------------------------
84SetEnv GIT_PROJECT_ROOT /var/www/git
85SetEnv GIT_HTTP_EXPORT_ALL
86ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
87
88# This is not strictly necessary using Apache and a modern version of
89# git-http-backend, as the webserver will pass along the header in the
90# environment as HTTP_GIT_PROTOCOL, and http-backend will copy that into
91# GIT_PROTOCOL. But you may need this line (or something similar if you
92# are using a different webserver), or if you want to support older Git
93# versions that did not do that copying.
94#
95# Having the webserver set up GIT_PROTOCOL is perfectly fine even with
96# modern versions (and will take precedence over HTTP_GIT_PROTOCOL,
97# which means it can be used to override the client's request).
98SetEnvIf Git-Protocol ".*" GIT_PROTOCOL=$0
99----------------------------------------------------------------
100+
101To enable anonymous read access but authenticated write access,
102require authorization for both the initial ref advertisement (which we
103detect as a push via the service parameter in the query string), and the
104receive-pack invocation itself:
105+
106----------------------------------------------------------------
107RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
108RewriteCond %{REQUEST_URI} /git-receive-pack$
109RewriteRule ^/git/ - [E=AUTHREQUIRED:yes]
110
111<LocationMatch "^/git/">
112 Order Deny,Allow
113 Deny from env=AUTHREQUIRED
114
115 AuthType Basic
116 AuthName "Git Access"
117 Require group committers
118 Satisfy Any
119 ...
120</LocationMatch>
121----------------------------------------------------------------
122+
123If you do not have `mod_rewrite` available to match against the query
124string, it is sufficient to just protect `git-receive-pack` itself,
125like:
126+
127----------------------------------------------------------------
128<LocationMatch "^/git/.*/git-receive-pack$">
129 AuthType Basic
130 AuthName "Git Access"
131 Require group committers
132 ...
133</LocationMatch>
134----------------------------------------------------------------
135+
136In this mode, the server will not request authentication until the
137client actually starts the object negotiation phase of the push, rather
138than during the initial contact. For this reason, you must also enable
139the `http.receivepack` config option in any repositories that should
140accept a push. The default behavior, if `http.receivepack` is not set,
141is to reject any pushes by unauthenticated users; the initial request
142will therefore report `403 Forbidden` to the client, without even giving
143an opportunity for authentication.
144+
145To require authentication for both reads and writes, use a Location
146directive around the repository, or one of its parent directories:
147+
148----------------------------------------------------------------
149<Location /git/private>
150 AuthType Basic
151 AuthName "Private Git Access"
152 Require group committers
153 ...
154</Location>
155----------------------------------------------------------------
156+
157To serve gitweb at the same url, use a ScriptAliasMatch to only
158those URLs that 'git http-backend' can handle, and forward the
159rest to gitweb:
160+
161----------------------------------------------------------------
162ScriptAliasMatch \
163 "(?x)^/git/(.*/(HEAD | \
164 info/refs | \
165 objects/(info/[^/]+ | \
166 [0-9a-f]{2}/[0-9a-f]{38} | \
167 pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
168 git-(upload|receive)-pack))$" \
169 /usr/libexec/git-core/git-http-backend/$1
170
171ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/
172----------------------------------------------------------------
173+
174To serve multiple repositories from different linkgit:gitnamespaces[7] in a
175single repository:
176+
177----------------------------------------------------------------
178SetEnvIf Request_URI "^/git/([^/]*)" GIT_NAMESPACE=$1
179ScriptAliasMatch ^/git/[^/]*(.*) /usr/libexec/git-core/git-http-backend/storage.git$1
180----------------------------------------------------------------
181
182Accelerated static Apache 2.x::
183 Similar to the above, but Apache can be used to return static
184 files that are stored on disk. On many systems this may
185 be more efficient as Apache can ask the kernel to copy the
186 file contents from the file system directly to the network:
187+
188----------------------------------------------------------------
189SetEnv GIT_PROJECT_ROOT /var/www/git
190
191AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/www/git/$1
192AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1
193ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
194----------------------------------------------------------------
195+
196This can be combined with the gitweb configuration:
197+
198----------------------------------------------------------------
199SetEnv GIT_PROJECT_ROOT /var/www/git
200
201AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/www/git/$1
202AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1
203ScriptAliasMatch \
204 "(?x)^/git/(.*/(HEAD | \
205 info/refs | \
206 objects/info/[^/]+ | \
207 git-(upload|receive)-pack))$" \
208 /usr/libexec/git-core/git-http-backend/$1
209ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/
210----------------------------------------------------------------
211
212Lighttpd::
213 Ensure that `mod_cgi`, `mod_alias`, `mod_auth`, `mod_setenv` are
214 loaded, then set `GIT_PROJECT_ROOT` appropriately and redirect
215 all requests to the CGI:
216+
217----------------------------------------------------------------
218alias.url += ( "/git" => "/usr/lib/git-core/git-http-backend" )
219$HTTP["url"] =~ "^/git" {
220 cgi.assign = ("" => "")
221 setenv.add-environment = (
222 "GIT_PROJECT_ROOT" => "/var/www/git",
223 "GIT_HTTP_EXPORT_ALL" => ""
224 )
225}
226----------------------------------------------------------------
227+
228To enable anonymous read access but authenticated write access:
229+
230----------------------------------------------------------------
231$HTTP["querystring"] =~ "service=git-receive-pack" {
232 include "git-auth.conf"
233}
234$HTTP["url"] =~ "^/git/.*/git-receive-pack$" {
235 include "git-auth.conf"
236}
237----------------------------------------------------------------
238+
239where `git-auth.conf` looks something like:
240+
241----------------------------------------------------------------
242auth.require = (
243 "/" => (
244 "method" => "basic",
245 "realm" => "Git Access",
246 "require" => "valid-user"
247 )
248)
249# ...and set up auth.backend here
250----------------------------------------------------------------
251+
252To require authentication for both reads and writes:
253+
254----------------------------------------------------------------
255$HTTP["url"] =~ "^/git/private" {
256 include "git-auth.conf"
257}
258----------------------------------------------------------------
259
260
261[[ENVIRONMENT]]
262ENVIRONMENT
263-----------
264'git http-backend' relies upon the `CGI` environment variables set
265by the invoking web server, including:
266
267* PATH_INFO (if GIT_PROJECT_ROOT is set, otherwise PATH_TRANSLATED)
268* REMOTE_USER
269* REMOTE_ADDR
270* CONTENT_TYPE
271* QUERY_STRING
272* REQUEST_METHOD
273
274The `GIT_HTTP_EXPORT_ALL` environment variable may be passed to
275'git-http-backend' to bypass the check for the "git-daemon-export-ok"
276file in each repository before allowing export of that repository.
277
278The `GIT_HTTP_MAX_REQUEST_BUFFER` environment variable (or the
279`http.maxRequestBuffer` config option) may be set to change the
280largest ref negotiation request that git will handle during a fetch; any
281fetch requiring a larger buffer will not succeed. This value should not
282normally need to be changed, but may be helpful if you are fetching from
283a repository with an extremely large number of refs. The value can be
284specified with a unit (e.g., `100M` for 100 megabytes). The default is
28510 megabytes.
286
287Clients may probe for optional protocol capabilities (like the v2
288protocol) using the `Git-Protocol` HTTP header. In order to support
289these, the contents of that header must appear in the `GIT_PROTOCOL`
290environment variable. Most webservers will pass this header to the CGI
291via the `HTTP_GIT_PROTOCOL` variable, and `git-http-backend` will
292automatically copy that to `GIT_PROTOCOL`. However, some webservers may
293be more selective about which headers they'll pass, in which case they
294need to be configured explicitly (see the mention of `Git-Protocol` in
295the Apache config from the earlier <<EXAMPLES,EXAMPLES>> section).
296
297The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' and
298GIT_COMMITTER_EMAIL to '$\{REMOTE_USER}@http.$\{REMOTE_ADDR\}',
299ensuring that any reflogs created by 'git-receive-pack' contain some
300identifying information of the remote user who performed the push.
301
302All `CGI` environment variables are available to each of the hooks
303invoked by the 'git-receive-pack'.
304
305GIT
306---
307Part of the linkgit:git[1] suite