How to rename master to main at Git

June 01, 2021

Do you want to have your main branch named to main instead of deprecated master? Not problem at all. You should check how you named your remote repo(s), it’s usually called origin. You can check it:

git remotes

And now you are ready to go:

git branch -m master main
git push -u origin main
git push origin --delete master

Do you see this error message?

 ! [remote rejected] master (deletion of the current branch prohibited)

Alright, you have to set the main branch in your remote GIT repository.

Bitbucket setup

And don’t forget to set the default branch in your local GIT repository:

git config --global init.defaultBranch main

Implement