Notes »

Self-hosting git repos

I blogged about it self-hosting git repos.

Adding a new repo

My repos are in /home/myuser/repos in my server.

How to add a new repo:

  1. Go to the repos directory.

  2. Create a directory:

mkdir my_repo_name
cd my_repo_name
git init --bare
  1. Set the hook for http support:

($PWD is stil “my_repo_name”)

cp hooks/post-update.sample hooks/post-update
  1. Edit decription, set the description.

  2. On your local copy the repo:

git remote add origin myuser@git.usebox.net:/home/myuser/repos/my_repo_name
git push origin main -u

Default branch “main”

If needed, for git 2.28 or later:

git config --global init.defaultBranch main

cgit specifics

These are only required/recommended if using cgit. Depending on versions and you local system you may not need all of it.

Set the repo owner

In my_repo_name directory edit config and add:

[gitweb]
        owner = My name <my email>

The about section doesn’t work

The default branch must be “main”, or the “about” section in cgit won’t work (check HEAD).

The “idle” column is not updating

To get the “idle” column working properly in the index page, add a cgitrc file with your default branch:

defbranch=main

(at least cgit v1.2.3 still checks for “master” by default)

“detected dubious ownership” error

It is likely that your repos are owned by the user updating them using ssh, and not by your webserver user running cgit (e.g. www-data) – which is a good idea!

If you can’t clone via https and you see error logs with detected dubious ownership messages, you can fix it with:

sudo git config --global --add safe.directory '*'

Go and read about safe.directory to ensure this is what you want to do!

Last updated Oct 2, 2024