The Default Git Branch
Published on 2020-06-17
For the eduVPN project I'm using two Git servers. My personal one, and GitHub as a mirror of those repositories.
For ages now we've had three branches: master, v1, and v2. All
development currently happens in the v2 branch, and master is lagging
behind a lot. On GitHub in the UI you can set the default branch to any other
branch, but how to do that on your own Git server with
cgit and how to actually delete the master
branch?
Turns out this quite easy to do! On my personal Git server I have the repositories
stored in /var/lib/git. The are in "bare" format there, obviously.
The repo.git directory contains a file HEAD with these contents:
ref: refs/heads/master
We can update this using the symbolic-ref Git command. How obscure?!
$ git symbolic-ref HEAD refs/heads/v2
The cool thing is that cgit picks this up automatically and uses that as the
default branch from now on. Also when you clone the repository the v2 branch
will be selected by default.
Next is deleting the master branch. Assuming the v2 branch at some point
was created from the master branch you can easily delete master now. If you
already have a cloned repository, you can also change the HEAD file in your
checked out repository:
$ git symbolic-ref HEAD refs/heads/v2
Now you can delete master:
$ git branch -d master
$ git push origin :master
Point your feed reader to the RSS Feed to keep up to date with new posts.