Git Reference ยท Remotes and Collaboration
git daemon and git http-backend
Reference for git daemon and git http-backend: serve repositories over git:// and smart HTTP, export-ok files, base paths, inetd mode and CGI environment variables.
Git can serve repositories itself. git daemon is a small server for the unauthenticated git:// protocol (port 9418). git http-backend is a CGI program that a web server such as nginx or Apache runs to provide the "smart HTTP" protocol, which supports both fetch and, with authentication, push. A third option, SSH, needs no special Git server at all: it just runs git-upload-pack and git-receive-pack on the remote machine.
Both servers speak the same protocol as git fetch and git push; they simply expose repositories under a root directory. Neither has users, permissions or a web interface of its own.
git daemon [--base-path=<dir>] [--export-all] [--enable=receive-pack] [--reuseaddr] [--detach] [<directory>...] git http-backend # CGI; configured by environment variables
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
git daemon options:
| Option | Description |
|---|---|
--base-path=<dir> |
Treat client paths as relative to this directory, so git://host/repo.git maps to <dir>/repo.git. |
--export-all |
Serve every repository found, without requiring a git-daemon-export-ok file. |
--enable=<service>, --disable=<service> |
Turn services on or off: upload-pack (on), upload-archive (off), receive-pack (off). |
--listen=<host>, --port=<n> |
Address and port (default 9418). |
--inetd |
Run for one connection on stdin/stdout, as started by inetd or systemd socket activation. |
--detach, --pid-file=<file>, --user=<user> |
Daemonize, record the process ID, drop privileges. |
--reuseaddr, --max-connections=<n>, --timeout=<s>, --init-timeout=<s> |
Operational limits. |
--strict-paths, --informative-errors |
Require exact repository paths; return error details to the client. |
<directory>... |
Whitelist: only repositories inside these directories are served. |
git http-backend environment variables:
| Variable | Meaning |
|---|---|
GIT_PROJECT_ROOT |
Directory that holds the repositories; PATH_INFO is appended to it. |
GIT_HTTP_EXPORT_ALL |
If set, serve repositories without the git-daemon-export-ok marker. |
PATH_INFO, QUERY_STRING, REQUEST_METHOD |
The usual CGI inputs. service=git-upload-pack selects fetch. |
REMOTE_USER |
Set by the web server after authentication; required for push unless http.receivepack is enabled. |
GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL |
Identity for the reflog of pushes. |
Errors: the daemon replies with an ERR packet such as access denied or repository not exported; http-backend answers 403 for a disabled service and 404 for an unknown repository.
Usage notes
git://has no authentication or encryption. Use it for read-only public mirrors on trusted networks. Enablingreceive-packon it allows anyone who can connect to push.- Smart HTTP behind a web server. Pass requests under, say,
/git/togit-http-backendwithGIT_PROJECT_ROOTset. Authentication, TLS and access control belong to the web server (basic auth, tokens, client certificates). - Dumb HTTP. A web server can also serve a repository's files statically. Run
git update-server-infoafter each push so the clients find refs and packs. It is slower and read-only. - Safety. Mark exported repositories explicitly with
git-daemon-export-okinstead of--export-all, and keep private repositories outside the base path. - Configuration:
daemon.uploadpack,daemon.receivepackanddaemon.uploadarchper repository;http.uploadpack,http.receivepackandhttp.getanyfilefor the CGI. - Stop typing the host. Clients use the same URLs as always; see URL rewriting and protocol settings.
- Production setups usually prefer SSH (with
git-shellfor restricted accounts) or a hosting platform; this pair is for simple internal servers, tests and embedding.