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.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Involved & Explore More

an abstract painting with blue and yellow colors

Catch up on what I’ve been writing lately.

Show your gratitude.

Join Dare To Code Email List

Get emails from me on full-stack PHP development by subscribing to the Dare To Code mailing list.