DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for How to rename your Github master branch
David Artiss
David Artiss

Posted on • Originally published at artiss.blog

How to rename your Github master branch

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.

Top comments (0)

DEV has this feature:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›