Thomas' Tech Tips

Serve git repository using built-in git daemon

22 March 2023 - Thomas Damgaard

I recently had to promote code from a development server to a production server. On the development server, I had a single Git repository. I wanted to be able to clone and pull this repository on the production server.

I was on a very limited system in which I could not install any additional software nor could I use an external git server such as GitHub, GitLab or Gitea.

The solution was to use the built-in git daemon.

This is how I did it:

Touch magic file

First, we need to create a magic file in order to allow git daemon to export the reposotiry.

On the development machine, run:

$ cd /dev_root/myproject
$ cd .git
$ touch git-daemon-export-ok

Run git daemon

Now it is time to run the actual git daemon. On the development machine, run:

$ cd /dev_root
$  git daemon --reuseaddr  --export-all --verbose --enable=receive-pack --base-path=. 
[4260] Ready to rumble

This will start the git daemon on port 9418.

Clone repository

On the production server, I can not clone the repository:

$ cd /prod
$ git clone git://devserver/myproject

Limitations

Access is completely unauthenticated. This means that anyone that can reach the git daemon over the network will be able to access the repository.

Access is read-only. This means that you can do git clone and git pull. But you will not be able to do write operations such as git push.

Filed under: git, howto, tips

Back to article list