Abstract
This is a second part to my other blog post concerning Git services. On the last post, I showed how to host a Git server with Forgejo; this time, I will be using Git daemon to setup a minimalist Git service.
The host for these notes is FreeBSD 14.0-RELEASE-p3 and has an IP address of 192.168.122.11.
Hosting Git with Git Daemon
The most minimal Git server possible will be just using
git-daemon
. It is included with Git and will give all of
the basic features of a Git repository, however, there are not many
features to Git daemon other than being able to sync Git
repositories.
doas pkg install git
cd ~
git init --bare repo1.git
git daemon --reuseaddr --export-all --enable=receive-pack
The repo can then be cloned by running
git clone git://192.168.122.11/home/${USER}/repo1.git
. At
this point, we have an extremely basic and simple Git server. There is
no thrills, frills, or even authentication due to the
--enable=recieve-pack
flag. However, without this flag, at
least without more setup, we would not be able to push changes to the
repos. That being said, this is what the git-daemon
man
page says about the receive-pack service:
receive-pack This serves git send-pack clients, allowing anonymous push. It is disabled by default, as there is no authentication in the protocol (in other words, anybody can push anything into the repository, including removal of refs). This is solely meant for closed LAN setting where everybody is friendly. This service can be enabled by setting daemon.receivepack configuration item to true.
So, while this is a way to accomplish the goal of having a remote Git
repo, it is not really a good way to do it unless you are very sure no
one will be inside your network doing anything nefarious. Git daemon
itself does not really have anything authentication built in, however,
we can interact with the Git server via SSH (which is how most Git
providers work). Doing this is as simple as changing the clone command:
git clone ssh://${USER}@192.168.122.11/home/${USER}/repo1.git
,
or if the repo has already been cloned, changing the remote source works
also:
git remote remove origin
git remote add origin ssh://${USER}@192.168.122.11/home/${USER}/repo1.git
doas pkg install git
doas mkdir -p /usr/local/git
git daemon --reuseaddr --base-path=/usr/local/git --export-all --user-path