Setting Up a Private Git Service

I was looking into setting up a private GitHub of sorts so that I could store some of my stuff. The main point of doing this is having independence from proprietary platforms of the likes of GitHub.

There are many many tools for that, such as GitLab (a complete DevOps platform which can be hosted locally) and Gitea (a collaborative code hosting thingy that uses git as it’s backbone), but most of them seemed a bit to complex for me.

All I want is a service I can push stuff to and have it render the repositories to HTML after each update, so I don’t need most of the sophisticate features provided by this platforms. Besides this, both GitLab and Gitea rely heavily in JavaScript, and as some of you may no I try to avoid using JavaScrip in my website AT ALL COASTS!

I ended up choosing something called stagit, which is “a static git page generator”. It’s fairly easy to set it up:

  1. Download the source code on your server from codemadness.org/stagit.html
  2. Compile the source code with $ make
  3. Copy the binaries to /usr/bin (or create a symlink)
  4. Chose a repository of your liking
  5. Move to the directory you want to store the rendered HTML
  6. Run $ stagit <PATH TO REPOSITORY>

If you want to create an index of your repositories you can run

$ stagit-index <PATH TO REPOSITORY>... > index.html

There’s still one missing peace of the puzzle though: we don’t really want to have to log-in to our server and run this every time we push a commit. To solve this, I created a simple shell script that automates this process:

make-stagit-repos

#!/bin/sh

makeStagitRepo() {
  repo="$1"
  reponame="$(basename "$repo")"
  target="/var/www/git/$reponame"
  echo "Updating the page for $reponame..."

  # Create the directory if it doesn't exist already
  if [ ! -d "$target" ]
  then
    mkdir "$target"
  fi

  # Run stagit on the appropriate directories
  cd "$target"
  stagit "$repo"
}

echo "Genrating global repository index..."
stagit-index /var/git/repos/* > /var/www/git/index.html

if [ -z "$1" ]
then
  for repo in /var/git/repos/*
  do
    makeStagitRepo "$repo"
  done
else
  makeStagitRepo "$1"
fi

echo "Done!"

I then configured the repositories on the server to run this script after each update by symlinking it to .git/hooks/post-update (or simply hooks/post-update if you’re using a bare repo). Make sure to provide the appropriate write-permissions to the git user.

I also had the modify the source code of stagit a bit to get it to render the HTML pages in the precise way I wanted them — see git.pablopie.xyz/stagit/log.html for more details. Anyway, the service is now up at git.pablopie.xyz! The only thing I still haven’t figured out to setup a link for people to clone the repos from, but I guess I’ll figure that out later.