DEV Community

Cover image for How to rename your Github master branch

How to rename your Github master branch

David Artiss
Support Engineer at WordPress VIP
Originally published at ・2 min read

So, whether for inclusion reasons (see various discussions about the use of master as a primary branch name) or just because you fancy a change, you'll find lots of people sharing Git commands on how to change the master branch name. But I want to target those people, like me, who favour the GUI over the command line (yes, yes, we do exist!).

Changing the branch name 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.
  2. This will copy your master repo to it.
  3. Now click on the branches link near the top.
  4. Click on “Change Default Branch”.
  5. On the next screen, change the default branch from “master” to the one you previously created and then press “Update”.
  6. You’ll be given a warning that you need to click through.
  7. Now, click back on that “Branches” link at the top again.
  8. 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.

Discussion (0)