aboutsummaryrefslogtreecommitdiffstats
path: root/posts/the_default_git_branch.md
blob: 724a2e9a480243d5930f8c7dccc8cb6148e4ecef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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