Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/Documentation/git-http-backend.adoc # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / Documentation / git-http-backend.adoc` 307 lines ยท 11691 bytes Raw Blame History 1 git-http-backend(1) 2 =================== 3 4 NAME 5 ---- 6 git-http-backend - Server side implementation of Git over HTTP 7 8 SYNOPSIS 9 -------- 10 [verse] 11 'git http-backend' 12 13 DESCRIPTION 14 ----------- 15 A simple CGI program to serve the contents of a Git repository to Git 16 clients accessing the repository over http:// and https:// protocols. 17 The program supports clients fetching using both the smart HTTP protocol 18 and the backwards-compatible dumb HTTP protocol, as well as clients 19 pushing using the smart HTTP protocol. It also supports Git's 20 more-efficient "v2" protocol if properly configured; see the 21 discussion of `GIT_PROTOCOL` in the <> section below. 22 23 It verifies that the directory has the magic file 24 "git-daemon-export-ok", and it will refuse to export any Git directory 25 that hasn't explicitly been marked for export this way (unless the 26 `GIT_HTTP_EXPORT_ALL` environment variable is set). 27 28 By 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, 31 the `receive-pack` service is enabled, which serves 'git send-pack' 32 clients, which is invoked from 'git push'. 33 34 SERVICES 35 -------- 36 These services can be enabled/disabled using the per-repository 37 configuration file: 38 39 http.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 47 http.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 52 http.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 59 http.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 63 URL TRANSLATION 64 --------------- 65 To determine the location of the repository on disk, 'git http-backend' 66 concatenates the environment variables PATH_INFO, which is set 67 automatically by the web server, and GIT_PROJECT_ROOT, which must be set 68 manually in the web server configuration. If GIT_PROJECT_ROOT is not 69 set, 'git http-backend' reads PATH_TRANSLATED, which is also set 70 automatically by the web server. 71 72 [[EXAMPLES]] 73 EXAMPLES 74 -------- 75 All of the following examples map `http://$hostname/git/foo/bar.git` 76 to `/var/www/git/foo/bar.git`. 77 78 Apache 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 ---------------------------------------------------------------- 84 SetEnv GIT_PROJECT_ROOT /var/www/git 85 SetEnv GIT_HTTP_EXPORT_ALL 86 ScriptAlias /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). 98 SetEnvIf Git-Protocol ".*" GIT_PROTOCOL=$0 99 ---------------------------------------------------------------- 100 + 101 To enable anonymous read access but authenticated write access, 102 require authorization for both the initial ref advertisement (which we 103 detect as a push via the service parameter in the query string), and the 104 receive-pack invocation itself: 105 + 106 ---------------------------------------------------------------- 107 RewriteCond %{QUERY_STRING} service=git-receive-pack [OR] 108 RewriteCond %{REQUEST_URI} /git-receive-pack$ 109 RewriteRule ^/git/ - [E=AUTHREQUIRED:yes] 110 111 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 121 ---------------------------------------------------------------- 122 + 123 If you do not have `mod_rewrite` available to match against the query 124 string, it is sufficient to just protect `git-receive-pack` itself, 125 like: 126 + 127 ---------------------------------------------------------------- 128 129 AuthType Basic 130 AuthName "Git Access" 131 Require group committers 132 ... 133 134 ---------------------------------------------------------------- 135 + 136 In this mode, the server will not request authentication until the 137 client actually starts the object negotiation phase of the push, rather 138 than during the initial contact. For this reason, you must also enable 139 the `http.receivepack` config option in any repositories that should 140 accept a push. The default behavior, if `http.receivepack` is not set, 141 is to reject any pushes by unauthenticated users; the initial request 142 will therefore report `403 Forbidden` to the client, without even giving 143 an opportunity for authentication. 144 + 145 To require authentication for both reads and writes, use a Location 146 directive around the repository, or one of its parent directories: 147 + 148 ---------------------------------------------------------------- 149 150 AuthType Basic 151 AuthName "Private Git Access" 152 Require group committers 153 ... 154 155 ---------------------------------------------------------------- 156 + 157 To serve gitweb at the same url, use a ScriptAliasMatch to only 158 those URLs that 'git http-backend' can handle, and forward the 159 rest to gitweb: 160 + 161 ---------------------------------------------------------------- 162 ScriptAliasMatch \ 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 171 ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/ 172 ---------------------------------------------------------------- 173 + 174 To serve multiple repositories from different linkgit:gitnamespaces[7] in a 175 single repository: 176 + 177 ---------------------------------------------------------------- 178 SetEnvIf Request_URI "^/git/([^/]*)" GIT_NAMESPACE=$1 179 ScriptAliasMatch ^/git/[^/]*(.*) /usr/libexec/git-core/git-http-backend/storage.git$1 180 ---------------------------------------------------------------- 181 182 Accelerated 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 ---------------------------------------------------------------- 189 SetEnv GIT_PROJECT_ROOT /var/www/git 190 191 AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/www/git/$1 192 AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1 193 ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/ 194 ---------------------------------------------------------------- 195 + 196 This can be combined with the gitweb configuration: 197 + 198 ---------------------------------------------------------------- 199 SetEnv GIT_PROJECT_ROOT /var/www/git 200 201 AliasMatch ^/git/(.*/objects/[0-9a-f]{2}/[0-9a-f]{38})$ /var/www/git/$1 202 AliasMatch ^/git/(.*/objects/pack/pack-[0-9a-f]{40}.(pack|idx))$ /var/www/git/$1 203 ScriptAliasMatch \ 204 "(?x)^/git/(.*/(HEAD | \ 205 info/refs | \ 206 objects/info/[^/]+ | \ 207 git-(upload|receive)-pack))$" \ 208 /usr/libexec/git-core/git-http-backend/$1 209 ScriptAlias /git/ /var/www/cgi-bin/gitweb.cgi/ 210 ---------------------------------------------------------------- 211 212 Lighttpd:: 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 ---------------------------------------------------------------- 218 alias.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 + 228 To 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 + 239 where `git-auth.conf` looks something like: 240 + 241 ---------------------------------------------------------------- 242 auth.require = ( 243 "/" => ( 244 "method" => "basic", 245 "realm" => "Git Access", 246 "require" => "valid-user" 247 ) 248 ) 249 # ...and set up auth.backend here 250 ---------------------------------------------------------------- 251 + 252 To 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]] 262 ENVIRONMENT 263 ----------- 264 'git http-backend' relies upon the `CGI` environment variables set 265 by 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 274 The `GIT_HTTP_EXPORT_ALL` environment variable may be passed to 275 'git-http-backend' to bypass the check for the "git-daemon-export-ok" 276 file in each repository before allowing export of that repository. 277 278 The `GIT_HTTP_MAX_REQUEST_BUFFER` environment variable (or the 279 `http.maxRequestBuffer` config option) may be set to change the 280 largest ref negotiation request that git will handle during a fetch; any 281 fetch requiring a larger buffer will not succeed. This value should not 282 normally need to be changed, but may be helpful if you are fetching from 283 a repository with an extremely large number of refs. The value can be 284 specified with a unit (e.g., `100M` for 100 megabytes). The default is 285 10 megabytes. 286 287 Clients may probe for optional protocol capabilities (like the v2 288 protocol) using the `Git-Protocol` HTTP header. In order to support 289 these, the contents of that header must appear in the `GIT_PROTOCOL` 290 environment variable. Most webservers will pass this header to the CGI 291 via the `HTTP_GIT_PROTOCOL` variable, and `git-http-backend` will 292 automatically copy that to `GIT_PROTOCOL`. However, some webservers may 293 be more selective about which headers they'll pass, in which case they 294 need to be configured explicitly (see the mention of `Git-Protocol` in 295 the Apache config from the earlier <> section). 296 297 The backend process sets GIT_COMMITTER_NAME to '$REMOTE_USER' and 298 GIT_COMMITTER_EMAIL to '$\{REMOTE_USER}@http.$\{REMOTE_ADDR\}', 299 ensuring that any reflogs created by 'git-receive-pack' contain some 300 identifying information of the remote user who performed the push. 301 302 All `CGI` environment variables are available to each of the hooks 303 invoked by the 'git-receive-pack'. 304 305 GIT 306 --- 307 Part of the linkgit:git[1] suite