Public read access for git repositories

This very short tutorial assumes that you have already installed gitolite. Gitolite itself does not provide public read access; it always requires an SSH key. That’s where git-daemon is needed, it will allow to git clone git:// .

Running the daemon

To run git-daemon as daemon on startup, install the git-daemon-run package. The daemon can then be started/stopped with:

# sv stop git-daemon
# sv start git-daemon

The file /etc/sv/git-daemon/run then needs to be adjusted as described here:

exec 2>&1
echo 'git-daemon starting.'
exec chpst -ugitdaemon:gitolite \
  "$(git --exec-path)"/git-daemon --verbose --reuseaddr --base-path=/var/lib/gitolite/repositories

File permissions

Cloning will not work yet since the gitolite repositories are set to rwx------ . As described in the gitolite documentation[1] the permissions for newly created files can be set in the .gitolite.rc file which is in gitolite’s home path, in this case at /var/lib/gitolite/.gitolite.rc .

$REPO_UMASK = 0027; # gets you 'rwxr-x---'

As only new files will set to rwxr-x--- now, the existing repositories which should be shared need to be updated.

# cd /var/lib/gitolite/repositories/
# chmod g+rX yourPublicRepo.git

Enabling sharing in gitolite

git-daemon only shares a repository if the file git-daemon-export-ok is available in its root directory. You could create it using touch path/to/repo.git/git-daemon-export-ok , but a more elegant way is to do this via the gitolite-admin repository[2] by giving the special user daemon read access. After pushing the changes to the server, gitolite will create the git-daemon-export-ok for you.

repo yourRepository RW+ = R = daemon

That’s it!


For the error messages check the error log on the server at /var/log/git-daemon/ , the most recent file is called current . The error message that is seen most frequently:

foo.git does not appear to be a git repository

[2994] Request upload-pack for '/foo.git' [2994] '/var/lib/gitolite/repositories/foo.git' does not appear to be a git repository [2992] [2994] Disconnected (with error)

This is usually a permission problem and can be fixed by following this tutorial closely. Especially check the following points:

It may also be a path problem. For example, on debian the base-path seems to be set to /var/cache by default, where you usually do not have any git repository.

Connection refused

Client error message (no error message on the server):

Cloning into foo... fatal: unable to connect to[0:]: errno=Connection refused

This error message is shown when the connection fails. (Obviously.) Either because git-daemon is not running (check with ps -e |grep git-daemon on the server), or because it has been restarted without using the --reuseaddr flag.

The first can be solved by starting the daemon (sv start git-daemon ), the second by adding the --reuseaddr flag and stopping and then starting the daemon again. You may have to wait for a minute or so first due to timeouts (see the daemon’s manpage).

  1. ^ .gitolite.rc documentation
  2. ^ gitolite-admin.git documentation