How to rename your `master` branch to `main` (or something else)

avatar
Ryan Block
July 15, 2020

Tree branches from below Photo by Carly Reeves

Terms like master-slave carry powerful implications of racial supremacy and oppression, and have no place in our lexicon. Efforts across our industry are rightfully underway to retire such references to the dustbin of history, where they belong.

Although Git and GitHub still name branches master by default (for now), moving your repos away from the master branch name is relatively easy. In this guide we’ll rename it main (or you can choose whatever you prefer). Some other ideas that have been bandied about include: default, dev, devel, primary, prod, release, and trunk.

Checklist

First, make sure you’ve gone over the following checklist to ensure you won’t be introducing any tricky side-effects:

Let’s go

Ok, let’s change that branch with git’s move flag (which is really more like a copy than a move, per se):

Then head to repository on GitHub and:

GitHub rename branch

Future collaborators will automatically be on main; existing contributors may have a small amount of work to do to get set up, namely:

Finally, only after you’ve migrated any dependent systems, your team has moved over locally, and you’re sure you’re ready to tidy up, delete the old master branch with: git push -d origin master

Next Steps

deploy-to-begin