path: root/posts/the_default_git_branch.md
diff options
authorFran├žois Kooman <fkooman@tuxed.net>2020-06-17 10:43:08 +0200
committerFran├žois Kooman <fkooman@tuxed.net>2020-06-17 10:43:08 +0200
commitb77654491c742c8cc97c601f968cb9345c18ada2 (patch)
tree056a4da2fa59e9c676bcaddd0400655a17f69de9 /posts/the_default_git_branch.md
parentd26b6e2b6a5a57c6056521b66adfba9d96e903d2 (diff)
add the_default_git_branch post
Diffstat (limited to 'posts/the_default_git_branch.md')
1 files changed, 41 insertions, 0 deletions
diff --git a/posts/the_default_git_branch.md b/posts/the_default_git_branch.md
new file mode 100644
index 0000000..724a2e9
--- /dev/null
+++ b/posts/the_default_git_branch.md
@@ -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`
+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