Git - Daemon



Git Daemon is a simple TCP server and it comes bundled with Git. It allows users to fetch and clone the repositories using git protocol.

Setting up a Git daemon for serving repositories via the Git protocol involves considering its unauthenticated nature. Hence it is useful in scenarios where you want Git repositiories to be served publicly with read-only access.

All data served by the Git daemon is publicly accessible within its network.

Key Features

Some of the key features of git daemon are as follows:

  • When deploying outside a firewall, restrict its use to projects intended for public visibility.

  • Within a firewall, the Git daemon can serve read-only access to projects accessible to multiple users or systems.

  • This includes scenarios like continuous integration or build servers.

  • Unlike SSH, Git daemon access does not require individual SSH keys for each user or system.

  • It is fast and consumes minimal system resources since it doesn't deal with authentication or encryption.

Setting Up Git Daemon

Following steps will set up and run the Git Daemon to serve repositiories over the Git protocol:

Install Git Daemon

Git Daemon is bundled with Git, so if you have Git installed, you will already have access to Git Daemon. Check for Git installation:

git --version

In case, Git is not installed, please install Git first. Use the following commands:

  • Ubuntu/Debian:

    sudo apt install git
  • CentOS/Fedora:

    sudo yum install git

Setting Up Repositories

Repositories need to be initialized as bare repositories since the git daemon is primarily for serving and not development.

Enabling the Repository for Git Daemon

You need to allow the Git Daemon exclusively so that it can serve the Git repositiories. In order to achieve this, create a file named git-daemon-export-ok inside the bare repository. This file is crucial as it is marked as a flag, which indicates that the repository can be served via Git protocol.

touch /path/to/repository.git/git-daemon-export-ok

Note: This file is important, as without it, the repository will not be exposed through the Git daemon.

Running the Git Daemon

Use the following command to invoke the Git Daemon:

git daemon --reuseaddr --base-path=/path/to/repositories --export-all --verbose --enable=receive-pack
  • --reuseaddr − It allows the git daemon to reuse the same address without waiting for timeout.

  • --base-path=/path/to/repositories − It specifies the directory where the Git daemon will serve repositories from.

  • --export-all − Under the base path, all the repositiories get exported, even if they don't have the git-daemon-export-ok file. This command should be used with caution.

  • --verbose − It enables detailed output for debugging processes.

  • --enable=receive-pack − It allows users to push to the repository. It is disabled by default for various security reasons.

Accessing Repositories via Git Daemon

As the daemon is running, you can clone or fetch from the repository using the git protocol. Have a look at an example:

git clone git://your_server_ip_or_hostname/repository.git

Benefits of Git Daemon

Following are some of the benefits of Git Daemon:

  • No authentication − It is ideal for public repositories where you do not need user-specific access controls.

  • Speed − As the Git protocol is lightweight and optimized for performance, it is faster than SSH and HTTP.

  • Easy Setup − It's setting is simple to configure and run.

Limitations of Git Daemon

Some of the limitations of Git Daemon are as follows:

  • No authentication − As this was a benefit, it is also a limitation. It can not be used for private repositories or situations where you need a secure access

  • Read-only − It is read-only by default. Though you can use the --enable=receive-pack option to push the changes, it is no recommended due to lack of authentication and security.

  • No encryption − Since encryption is not taken care by the git protocol, it is unsafe to transfer the secured and sensitive data.

In case you need authentication and encryption, the alternative to be considered for private repositories to be used is either SSH or HTTPS.

Advertisements