Renaming Git's Master Branch

Published 2020-06-19

Today I spent about an hour renaming the master branch to main on all my personal repositories. This included around 100 repos in GitHub, Bitbucket and Azure DevOps. To be clear, I don’t think this is going to be the thing that fixes racism in our society. I’ve heard people (mostly on Twitter) argue against this change, however:

  • If we’re going to argue over such small things, what hope is there to get anything big done?
  • If the word “master” hurts even just a few people, then this change is worth my time.
  • If this change brings even a little more awareness, it’s worth my time.

How to Change master to main

It seems that most people are settling on main as the replacement for master. If you’d like to make such changes to your repositories, the general steps are:

  • Make sure that any local changes have been pushed to master
  • Create a new branch called main and make sure it is based off of master
  • If you have any CI setup on master, switch it over to main
  • Configure main as your main/default branch
  • Delete master
  • Locally run git pull followed by git checkout main

Below are some screenshots and specific details of the three platforms I use:

GitHub

You can create a new branch in Github directly on the main “code” page of the repo:

GitHub Create Branch

If you have any open pull requests, you’ll need to edit them and switch the base branch to main:

GitHub Change Pull Request Base Branch

You can find a link to change the default branch on the “branches” page of your repo:

GitHub Change Default Branch

Bitbucket

You can create a new branch in Bitbucket here:

Bitbucket Create Branch

Pull Request target branch will need to be changed here:

Bitbucket Update Pull Requests

The main branch can be updated under the repository’s settings:

Bitbucket Change Main Branch

Azure Devops

In Azure DevOps you can create here:

Azure DevOps Create Branch

You can then change the default branch here:

Azure DevOps Set Default Branch

The End

That’s all there is to it!

comments powered by Disqus