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