Before renaming your master
branch to main
in git, keep in mind anywhere you are using the master
branch should also be updated. For example, you might have apps, CI, team members, deployment scripts, and others using the master branch. Be sure to update all of these places immediately after changing your branch to main
.
Rename master
to main
From your local git repository.
git branch -m master main
git push -u origin main
If you are using GitHub, from repo go to “Settings > Branches > Default Branch” and update the default branch to “main”. You can delete the master branch from your local and origin locations.
git push origin --delete master
Finally, if you are using multiple computers or have team members that need to remove the master branch they can run the following.
git checkout master
git branch -m master main
git fetch
git branch --unset-upstream
git branch -u origin/main
If you need more detailed instructions check out the GitTower post on the topic.
Leave a Reply