Renaming "master" to "main"
For the longest time, the default branch in most Git repositories was named "master". Fortunately, many people have become aware that this terminology (even more evident in "master/slave") should be replaced! The tech industry should move to a more inclusive, open culture - and removing language like "master/slave" is an important step in this journey.
In the public discussion, a handful of different alternatives for "master" have popped up, "default" and "primary" being some of them. But the most popular term seems to be "main".
This short article will help you rename "master" in your own Git repositories to "main" (or any other term your team has chosen).
Step 1: Rename Your Local Branch
First of all, you should rename your local "master" branch to "main". You can do that simply by right-clicking the branch in the sidebar and then choosing the "Rename..." option from the contextual menu.
Step 2: Push the Renamed Local Branch to the Remote
As a second step, you need to publish your new (or, more appropriately: renamed) "main" branch on your remote repository. You can do so by dragging it in the sidebar and dropping it onto the remote (e.g. "origin").
Step 3: Delete the Old "master" Branch on the Remote
What's left is to delete the old "master" branch on the remote repository. You can simply try right-clicking that branch in the sidebar and choose the "Delete..." option from the contextual menu.
Chances are, however, that you will be presented with an error message! The reason for this is that in many Git hosting platforms (e.g. GitHub and Gitlab), you have to change the "default" branch or remove any "protected" status for "master". You will then be able to delete the old "master" branch on the remote.
As an example, here's how to do this in GitHub:
If you try again now, deleting "master" from the remote repository should be successful!
What Your Teammates Have to Do
If other people on your team have local clones of the repository, they will also have to perform some steps on their end. Here's an overview of what they have to do:
- Check out the "master" branch
- Rename it to "main"
- Get the latest commits (and branches!) from the remote by performing a "Fetch"
- Remove the existing tracking connection with "origin/master"
- Create a new tracking connection with the new "origin/main" branch
Take a look at the following video to see those steps in action:
Things to Keep in Mind
As you've seen, the process of renaming "master" to "main" isn't terribly complicated.
One thing to keep in mind, though, is your toolchain: if you're using a CI/CD tool, GitHub Actions, Azure DevOps / Atlassian Bamboo / GitLab CI pipelines or anything like this, you should check these tools thoroughly. If they depend on a specific "origin/master" branch, you might have to change their settings, too.