AbstractBrain Answers About us →

Git: how to rename branch master to main


How can I rename git branch master to main?

I see that many projects are moving from master to main.

What is the easiest way to rename the master branch to main?

How can I rename it also on the Github repo without breaking things?

Should I do it for all projects or I can keep using master (all my projects use branch master)?


Many people are moving from branch master to main.

Personally I find this change meaningless and confusing — nobody thinks to slavery when you talk about master and slave in computer science and it is just a convention! Also note that master is still the default name for Git.

In any case if you want to follow the majority of companies that are changing the name from master to main, you can do it with one simple command:

$ git branch -m master main

Then you can ensure that you are on branch main with git status.

After the change you can use:

$ git push origin main

Note that also the other commands will change. For example if you want to push on Heroku:

$ git push heroku main

Finally… If you ever want to switch back from main to master you can also do it: just switch the position of master and main in the git branch command.

Note that for Git the branch master (or main) doesn’t have any special meaning, it’s just a branch like any other.