~fkooman/www.tuxed.net

b77654491c742c8cc97c601f968cb9345c18ada2 — François Kooman 9 months ago d26b6e2
add the_default_git_branch post
1 files changed, 41 insertions(+), 0 deletions(-)

A posts/the_default_git_branch.md
A posts/the_default_git_branch.md => posts/the_default_git_branch.md +41 -0
@@ 0,0 1,41 @@
---
title: The Default Git Branch
published: 2020-06-17
---

For the [eduVPN](https://www.eduvpn.org/) 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](https://git.zx2c4.com/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