Contents

Change Git Default Branch Name


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. Change the branch name locally

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.


2. Push new branch to remote upstream

1
git push -u origin main

-u option is used to set the upstream


3. Change HEAD pointer to new branch

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.

4. Change default branch in the repo host

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


5. Delete old upstream branch

1
git push origin --delete master