OpenBSD Git server with stagit(1) Web frontend

Table of contents

  1. Setting up a Git subdomain
  2. Frontend HTTP configuration
  3. Setting up the Git server
  4. Pushing chagnes to the server
  5. stagit(1) web frontend

Setting up a Git subdomain

It's good to have your Git server under a subdomain, so that it looks like To do that, add a new CNAME record for the subdomain on your registrar. If you're on Epik, don't forget the trailing period after the domain name.

	Host: git | Points to:

Frontend HTTP configuration

I've already covered how to set up a website here. Obviously, use the subdomain name you just created.

Setting up the Git server

Install git:

	# pkg_add git

Create a git user and give it a password:

	# adduser git

If you don't want the same hosts that exist in your current user's authorized_keys to have access to the Git server, then add their keys manually in the git user's .ssh/authorized_keys file. In my case, it's just me who has access to the server, so I will not edit anything:

	# cp -r $HOME/.ssh /home/git/

Change the owner and group to git:

	# chown -R git:git /home/git/.ssh

Try sshing to the server as git from your local computer just to test if it works:

	$ ssh 

If it worked, exit the session.

Set up a Git directory where all repositories will be stored at and cd into it:

	# mkdir /var/www/htdocs/
	# chown -R git:git /var/www/htdocs/
	# cd /var/www/htdocs/

Say I want to create a repository named repo. The structure your repositories should have is name.git, so in this case it'll be repo.git:

	# mkdir repo.git

Create a bare repository inside it:

	# git init --bare repo.git

In order for stagit(1) to show everything properly, we have to write a few files inside the repository:

Replace each text inside double quotes with what you want it to be:

	# echo "John Doe" > repo.git/.git/owner
	# echo "This is a repo" > repo.git/.git/description
	# echo "git://" > repo.git/.git/url

To be able to interact with the Git server, the repository's owner needs to be the git user you created earlier:

	# chown -R git:git repo.git

Since sometimes the Git server by default might not be listening on port 9418 (the default Git port), which means that you'll not be able to clone repositories from the Git server, you have to set up the daemon yourself using a massive git command. You can (in fact, you should) also use Git over HTTPS or SSH, but for now I'll be using the default Git protocol for cloning and SSH for pushing.

	# git daemon --base-path=/var/www/htdocs/ --export-all --enable=receive-pack --reuseaddr --informative-errors --verbose --detach

Pushing changes to the server

On your local machine, make a repository for repo (the repository you created earlier) and add a few files so that you have something to commit and push to the server:

	$ mkdir repo && cd repo
	$ touch foo bar
	$ git init
	$ git add .
	$ git commit -m "initial commit"

In order to be able to push you have to edit .git/config. If you've used GitHub before, you might have noticed that when you want to push, you push to origin; for this server I'll use home, but you can use whatever else you want, it doesn't really matter.

Append the following block to your repository's .git/config and of course replace the domain and repository names with your own ones:

	[remote "home"]
		url =
		fetch = +refs/heads/*:refs/remotes/home/*

Push to the Git server:

	$ git push home master

Try also cloning the repository to make sure that everything works:

	$ git clone git://

If that step was successful too, great, you now have a working Git server. :-)

stagit(1) web frontend

I'm going to show you the bare minimum you need to do for stagit(1) to work. If you're interested in learning more about what you can do with it, you can here.

Install stagit(1):

	# git clone git://
	# cd stagit
	# doas make install clean

What stagit(1) essentially does is it reads Git repositories and generates static pages for them with a predefined CSS stylesheet (I said stylesheet twice!), a website logo and a favicon.

I like to have everything stagit(1)-related inside /var/www/htdocs/ along with the actual repositories, but you can choose any other directory if you don't like this and feel like it's too cluttered.

First, store the stylesheet, logo and favicon inside /var/www/htdocs/ You'll find the stylesheet inside the stagit(1) repository you cloned earlier; it's called style.css. For the logo and favicon, just make your own, but make sure they are in PNG format and have the same names as below.

	# cp logo.png favicon.png style.css /var/www/htdocs/

You can edit the stylesheet to your likings, but if you're afraid that you'll mess things up, play around with the colors only.

Earlier I created a repository named repo in /var/www/htdocs/ I will now make a directory to store the files that stagit(1) will produce. I like to give it the same name with the repository but without the .git extension:

	# mkdir /var/www/htdocs/
	# cd /var/www/htdocs/

Create symlinks for the stylesheet, logo and favicon inside the directory you just created:

	# ln -s ../style.css ../logo.png ../favicon.png .

Run stagit(1) and generate the static page for your repository. This has to be done inside the directory you just created since stagit(1) stores the files in the working directory. Make sure that you give it the .git directory (i.e the actual repository):

	# stagit ../repo.git

Go to the top-level Git directory and generate an index.html file which is your Git server's homepage where all repositories will be listed. Again, you give it the actual repositories:

	# cd /var/www/htdocs/
	# stagit-index repo.git > index.html

Fire up a browser and go to and you should see everything. Success!