Self-Host Git Repositories with Stagit


By following these steps, I moved my repositories from Codeberg to this website. I skipped a few parts since I authorized my ssh key under NearlyFreeSpeech's member profile page, and I don't have root access to create a git user.

Different directories can be made to separate the bare repos' files from the ones generated by stagit, but I prefer keeping them together. If you decide on using one folder, make sure that there are not any rules in .htaccess that automatically remove the .html extension so that refs.html is not redirected to the refs/ folder.

cd /home/public
mkdir git
cd $_
git init --bare test

On your machine, you can now git clone user@host:git/test or git remote add origin user@host:git/test in an already existing repo. To clone it read-only over HTTPS, mv hooks/post-update.sample hooks/post-update. It can run now instead of waiting to push with sh hooks/post-update.

I tried allowing access over the git protocol, but I got the error message below. Information on protocols are available here.

$ git clone git://riazj.com/git/riazj.com
Cloning into 'riazj.com'...
fatal: unable to connect to riazj.com:
riazj.com[0: 2607:ff18:80:4::6db8]: errno=No route to host
riazj.com[1: 208.94.117.16]: errno=Network is unreachable

Back on the host, install stagit.

cd /home/private
git clone git://git.codemadness.org/stagit
cd stagit
make
make install

I set PREFIX to ~/stagit in the makefile and ran the command below to include the executables in my PATH.

echo 'export PATH="/home/private/stagit/bin:$PATH"' >> ~/.zshrc

Copy your logo and favicon if needed and stagit/style.css to your git folder. Inside a repo, run the following commands to set the owner, description, and URL for cloning.

echo "Riaz" > owner
echo "test repo" > description
echo "https://riazj.com/git/test" > url

Modify stagit/example_post-receive.sh for your use case and place it at hooks/post-receive for each git repo. Consider symlinking it. I use this post-receive hook to generate the stagit pages in the same folders as the bare repos.

If you ran stagit on a repo and later change the description, running stagit again will not show this change on all files unless the commit folder was removed first. Alternatively, you can manually edit the HTML.