Development WordPress

How to rename your Github master branch

There’s a lot of discussion right now about the default Git branch of master and about renaming itself to something more inclusive.

I’m going to take you through a little of the background to why this is occurring and how to do it in Github.

What’s the problem with the branch name?

Use of the word master is problematic, particularly if it’s in relation to any kind of master/slave relationship, in preference to the alternative of something as an original.

In the case of Git, some research shows it’s historically down to the former.

And it looks as if there are wider plans afoot for future.

What to change it to?

The main candidates are main, trunk, and source. Thankfully, Johannes Schindelin, the maintainer of Git for Windows has already done some research on this

“Trunk” has roots in SVN so there’s some
precedent for it, but we’ve heard feedback that it’s not
particularly intuitive for non-native English speakers, and “source”
in my opinion isn’t accurate because it’s only a single branch, not
the entire source. We’ve also seen “default” floated and it exists
in mercurial, but we’ve also heard feedback that it’s potentially
sensitive due to financial default, so we might as well choose
something else if there’s another good option.

For that reason, we’re thinking that main would likely be a good
choice because the name corresponds nicely to its purpose as the
default branch of a repo.

Hey, it’s really easy to rename it in Git

Yes, turn to social media and you’ll find lots of people listing the Git commands required, from the command line, to change this but, in my opinion, the kind of person who uses Git from the command line is probably not the kind of person who would struggle to know how to rename a branch.

Instead, I want to target the more amateur user, who’s likely to be using Github.

Renaming the branch in Github

The issue here is that Github doesn’t give you a rename option. Instead, we need to create a new repo, a duplicate of the master, make it the new, default branch and then remote master. Thankfully, it’s not too difficult.

  1. On your repo’s main Github page, click on the branches dropdown and create a new branch. I’m calling mine main.
  1. This will copy your master repo to it.
  2. Now click on the branches link near the top.
  1. Click on “Change Default Branch”
  1. On the next screen, change the default branch from “master” to the one you previously created and then press “Update”.
  1. You’ll be given a warning that you need to click through.
  2. Now, click back on that “Branches” link at the top again.
  3. The final thing to do is to remove your old master branch – just press the trash/bin icon next to it to do this.

And that’s it. Your master branch has now been replaced.

What about Github Desktop?

Good call – for your changes to be reflected in Github’s desktop app, you need to do something. Maybe.

Click on Fetch Origin to force the desktop app to update the repo. Now, this works but you’ll also your old master branch still present…

Personally, I’ve found it easiest just to delete it and re-clone the repo.

Talk to me!

This site uses Akismet to reduce spam. Learn how your comment data is processed.