Change Git Default Branch Name

Contents

All git repositories used to use the master as the branch name, but it was changed to main since October, 2020. Here are steps to change default branch name for existing projects.

1
git branch -m master main

-m option is used to rename the branch name with all of the commit history transfer to new branch.


1
git push -u origin main

-u option is used to set the upstream


1
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
Note
You can use git branch -a to check which branch HEAD points to.

In github, gitlab or bitbucket, go to settings -> branches and change the default branch name from ‘master’ to ‘main’. /assets/git-change-default-branch-name.assets/git-rename.png


1
git push origin --delete master