blob: 3ca18c4de519ebdf0a2af6509d0d6bed3e6e492c [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
19pushing using the smart HTTP protocol.
20
Junio C Hamano6ce6b6c2010-01-18 01:25:5021It verifies that the directory has the magic file
Junio C Hamano076ffcc2013-02-06 05:13:2122"git-daemon-export-ok", and it will refuse to export any Git directory
Junio C Hamano6ce6b6c2010-01-18 01:25:5023that hasn't explicitly been marked for export this way (unless the
24GIT_HTTP_EXPORT_ALL environmental variable is set).
25
Junio C Hamano3b70d3c2009-11-21 17:37:3726By default, only the `upload-pack` service is enabled, which serves
Junio C Hamano1aa40d22010-01-21 17:46:4327'git fetch-pack' and 'git ls-remote' clients, which are invoked from
28'git fetch', 'git pull', and 'git clone'. If the client is authenticated,
29the `receive-pack` service is enabled, which serves 'git send-pack'
30clients, which is invoked from 'git push'.
Junio C Hamano3b70d3c2009-11-21 17:37:3731
32SERVICES
33--------
34These services can be enabled/disabled using the per-repository
35configuration file:
36
37http.getanyfile::
Junio C Hamano1f630d52010-04-01 04:49:2538This serves Git clients older than version 1.6.6 that are unable to use the
Junio C Hamano3b70d3c2009-11-21 17:37:3739upload pack service. When enabled, clients are able to read
40any file within the repository, including objects that are
41no longer reachable from a branch but are still present.
42It is enabled by default, but a repository can disable it
43by setting this configuration item to `false`.
44
45http.uploadpack::
Junio C Hamano1aa40d22010-01-21 17:46:4346This serves 'git fetch-pack' and 'git ls-remote' clients.
Junio C Hamano3b70d3c2009-11-21 17:37:3747It is enabled by default, but a repository can disable it
48by setting this configuration item to `false`.
49
50http.receivepack::
Junio C Hamano1aa40d22010-01-21 17:46:4351This serves 'git send-pack' clients, allowing push. It is
Junio C Hamano3b70d3c2009-11-21 17:37:3752disabled by default for anonymous users, and enabled by
53default for users authenticated by the web server. It can be
54disabled by setting this item to `false`, or enabled for all
55users, including anonymous users, by setting it to `true`.
56
57URL TRANSLATION
58---------------
Junio C Hamano1aa40d22010-01-21 17:46:4359To determine the location of the repository on disk, 'git http-backend'
Junio C Hamano3b70d3c2009-11-21 17:37:3760concatenates the environment variables PATH_INFO, which is set
61automatically by the web server, and GIT_PROJECT_ROOT, which must be set
62manually in the web server configuration. If GIT_PROJECT_ROOT is not
Junio C Hamano1aa40d22010-01-21 17:46:4363set, 'git http-backend' reads PATH_TRANSLATED, which is also set
Junio C Hamano3b70d3c2009-11-21 17:37:3764automatically by the web server.
65
66EXAMPLES
67--------
Junio C Hamano1dbca522015-05-22 20:48:5568All of the following examples map `http://$hostname/git/foo/bar.git`
69to `/var/www/git/foo/bar.git`.
Junio C Hamano3b70d3c2009-11-21 17:37:3770
71Apache 2.x::
72Ensure mod_cgi, mod_alias, and mod_env are enabled, set
73GIT_PROJECT_ROOT (or DocumentRoot) appropriately, and
74create a ScriptAlias to the CGI:
75+
76----------------------------------------------------------------
77SetEnv GIT_PROJECT_ROOT /var/www/git
Junio C Hamano6ce6b6c2010-01-18 01:25:5078SetEnv GIT_HTTP_EXPORT_ALL
Junio C Hamano3b70d3c2009-11-21 17:37:3779ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
80----------------------------------------------------------------
81+
82To enable anonymous read access but authenticated write access,
Junio C Hamanoe3f080d2013-04-22 02:27:1383require authorization for both the initial ref advertisement (which we
84detect as a push via the service parameter in the query string), and the
85receive-pack invocation itself:
86+
87----------------------------------------------------------------
88RewriteCond %{QUERY_STRING} service=git-receive-pack [OR]
89RewriteCond %{REQUEST_URI} /git-receive-pack$
90RewriteRule ^/git/ - [E=AUTHREQUIRED:yes]
91
92<LocationMatch "^/git/">
93Order Deny,Allow
94Deny from env=AUTHREQUIRED
95
96AuthType Basic
97AuthName "Git Access"
98Require group committers
99Satisfy Any
100...
101</LocationMatch>
102----------------------------------------------------------------
103+
104If you do not have `mod_rewrite` available to match against the query
105string, it is sufficient to just protect `git-receive-pack` itself,
106like:
Junio C Hamano3b70d3c2009-11-21 17:37:37107+
108----------------------------------------------------------------
109<LocationMatch "^/git/.*/git-receive-pack$">
110AuthType Basic
111AuthName "Git Access"
112Require group committers
113...
114</LocationMatch>
115----------------------------------------------------------------
116+
Junio C Hamanoe3f080d2013-04-22 02:27:13117In this mode, the server will not request authentication until the
118client actually starts the object negotiation phase of the push, rather
119than during the initial contact. For this reason, you must also enable
120the `http.receivepack` config option in any repositories that should
121accept a push. The default behavior, if `http.receivepack` is not set,
122is to reject any pushes by unauthenticated users; the initial request
123will therefore report `403 Forbidden` to the client, without even giving
124an opportunity for authentication.
125+
Junio C Hamano3b70d3c2009-11-21 17:37:37126To require authentication for both reads and writes, use a Location
127directive around the repository, or one of its parent directories:
128+
129----------------------------------------------------------------
130<Location /git/private>
131AuthType Basic
132AuthName "Private Git Access"
133Require group committers
134...
135</Location>
136----------------------------------------------------------------
137+
138To serve gitweb at the same url, use a ScriptAliasMatch to only
Junio C Hamano1aa40d22010-01-21 17:46:43139those URLs that 'git http-backend' can handle, and forward the
Junio C Hamano3b70d3c2009-11-21 17:37:37140rest to gitweb:
141+
142----------------------------------------------------------------
143ScriptAliasMatch \
144"(?x)^/git/(.*/(HEAD | \
145info/refs | \
146objects/(info/[^/]+ | \
147 [0-9a-f]{2}/[0-9a-f]{38} | \
148 pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
149git-(upload|receive)-pack))$" \
150/usr/libexec/git-core/git-http-backend/$1
151
152ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/
153----------------------------------------------------------------
Junio C Hamanof7279012011-08-18 06:13:13154+
155To serve multiple repositories from different linkgit:gitnamespaces[7] in a
156single repository:
157+
158----------------------------------------------------------------
159SetEnvIf Request_URI "^/git/([^/]*)" GIT_NAMESPACE=$1
160ScriptAliasMatch ^/git/[^/]*(.*) /usr/libexec/git-core/git-http-backend/storage.git$1
161----------------------------------------------------------------
Junio C Hamano3b70d3c2009-11-21 17:37:37162
163Accelerated static Apache 2.x::
164Similar to the above, but Apache can be used to return static
165files that are stored on disk. On many systems this may
166be more efficient as Apache can ask the kernel to copy the
167file contents from the file system directly to the network:
168+
169----------------------------------------------------------------
170SetEnv GIT_PROJECT_ROOT /var/www/git
171
172AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/www/git/$1
173AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1
174ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/
175----------------------------------------------------------------
176+
177This can be combined with the gitweb configuration:
178+
179----------------------------------------------------------------
180SetEnv GIT_PROJECT_ROOT /var/www/git
181
182AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/www/git/$1
183AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1
184ScriptAliasMatch \
185"(?x)^/git/(.*/(HEAD | \
186info/refs | \
187objects/info/[^/]+ | \
188git-(upload|receive)-pack))$" \
189/usr/libexec/git-core/git-http-backend/$1
190ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/
191----------------------------------------------------------------
192
Junio C Hamanoe3f080d2013-04-22 02:27:13193Lighttpd::
Junio C Hamano58242b72014-04-09 20:58:48194Ensure that `mod_cgi`, `mod_alias`, `mod_auth`, `mod_setenv` are
Junio C Hamanoe3f080d2013-04-22 02:27:13195loaded, then set `GIT_PROJECT_ROOT` appropriately and redirect
196all requests to the CGI:
197+
198----------------------------------------------------------------
199alias.url += ( "/git" => "/usr/lib/git-core/git-http-backend" )
200$HTTP["url"] =~ "^/git" {
201cgi.assign = ("" => "")
202setenv.add-environment = (
203"GIT_PROJECT_ROOT" => "/var/www/git",
204"GIT_HTTP_EXPORT_ALL" => ""
205)
206}
207----------------------------------------------------------------
208+
209To enable anonymous read access but authenticated write access:
210+
211----------------------------------------------------------------
212$HTTP["querystring"] =~ "service=git-receive-pack" {
213include "git-auth.conf"
214}
215$HTTP["url"] =~ "^/git/.*/git-receive-pack$" {
216include "git-auth.conf"
217}
218----------------------------------------------------------------
219+
220where `git-auth.conf` looks something like:
221+
222----------------------------------------------------------------
223auth.require = (
224"/" => (
225"method" => "basic",
226"realm" => "Git Access",
227"require" => "valid-user"
228 )
229)
230# ...and set up auth.backend here
231----------------------------------------------------------------
232+
233To require authentication for both reads and writes:
234+
235----------------------------------------------------------------
236$HTTP["url"] =~ "^/git/private" {
237include "git-auth.conf"
238}
239----------------------------------------------------------------
240
Junio C Hamano3b70d3c2009-11-21 17:37:37241
242ENVIRONMENT
243-----------
Junio C Hamano1aa40d22010-01-21 17:46:43244'git http-backend' relies upon the CGI environment variables set
Junio C Hamano3b70d3c2009-11-21 17:37:37245by the invoking web server, including:
246
247* PATH_INFO (if GIT_PROJECT_ROOT is set, otherwise PATH_TRANSLATED)
248* REMOTE_USER
249* REMOTE_ADDR
250* CONTENT_TYPE
251* QUERY_STRING
252* REQUEST_METHOD
253
Junio C Hamano6ce6b6c2010-01-18 01:25:50254The GIT_HTTP_EXPORT_ALL environmental variable may be passed to
255'git-http-backend' to bypass the check for the "git-daemon-export-ok"
256file in each repository before allowing export of that repository.
257
Junio C Hamano3b70d3c2009-11-21 17:37:37258The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' and
259GIT_COMMITTER_EMAIL to '$\{REMOTE_USER}@http.$\{REMOTE_ADDR\}',
260ensuring that any reflogs created by 'git-receive-pack' contain some
261identifying information of the remote user who performed the push.
262
263All CGI environment variables are available to each of the hooks
264invoked by the 'git-receive-pack'.
265
Junio C Hamano3b70d3c2009-11-21 17:37:37266GIT
267---
268Part of the linkgit:git[1] suite