1

I'm trying to configure my own git repository server with Git SmartHTTP and Apache2. So followed these instuctions from the official git manual. But during the configuration it becomes not clear to me, what the GIT_PROJECT_ROOT variable exactly configures: Does it set the path to exactly one repository on a webserver or can you set it's value to a folder path which contains all your repositories.
And what other things does this variable affects?
The problem is that there is no description or explanation in the official git manual neither in the SmartHTTP chapter nor in the environment variables chapter.

1

There is a description in the git-http-backend manual. Variable GIT_PROJECT_ROOT is set to a parent path of all repositories and similar to the Apache DocumentRoot directive, it is used to translate an URL-path to the filesystem:

URL TRANSLATION

To determine the location of the repository on disk, git http-backend concatenates the environment variables PATH_INFO, which is set automatically by the web server, and GIT_PROJECT_ROOT, which must be set manually in the web server configuration. If GIT_PROJECT_ROOT is not set, git http-backend reads PATH_TRANSLATED, which is also set automatically by the web server.

EXAMPLES

All of the following examples map http://$hostname/git/foo/bar.git to /var/www/git/foo/bar.git.

Apache 2.x

Ensure mod_cgi, mod_alias, and mod_env are enabled, set GIT_PROJECT_ROOT (or DocumentRoot) appropriately, and create a ScriptAlias to the CGI:

SetEnv GIT_PROJECT_ROOT /var/www/git
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/

So the /git/ part in http://hostname/git/foo/bar.git is mapped to the git-http-backend CGI script and the remaining part foo/bar.git is appended to the path of the GIT_PROJECT_ROOT (or DocumentRoot) variable which should match a Git repo.

3
  • So if I get it right, an incoming request to the webserver just reaches the http://hostname/git part of the url and the foo/bar.git part (which resides inside the PATH_INFO variable) is combined with the GIT_PROJECT_ROOT to access the repository itself. And secondly, is this the reason why the webserver returns a 404 error if you're trying to access the http://hostname/git/ folder in your webbrowser?
    – Daniel
    Nov 4 '19 at 14:34
  • (1) Yes and (2) I would guess that depends on your Apache configuration, i.e. if it finds an index.html, index.php or whatever (see DirectoryIndex) or if directory listings are allowed (Options Indexes). Look into your Apache error.log if there is more information.
    – Freddy
    Nov 4 '19 at 18:41
  • The problem occured because of my Apache2 configuration: The ScriptAlias setting had the same url path (/repos/git) as the repositories on the local filesystem (DocumentRoot /repos/git). So if you call http://hostname/git the webserver passed the request always to the CGI script instead of serving the files to the webbrowser. Setting ScriptRoot to a fictive path (/git/) and let the repos reside in /repos/git solved it.
    – Daniel
    Nov 4 '19 at 19:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.