Moving a git ‘master’ branch to ‘main’
source link: https://www.kevinhooke.com/2021/10/26/moving-a-git-master-branch-to-main/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Moving a git ‘master’ branch to ‘main’
By default, the git install on my MacOS 11.5 creates new projects with a ‘master’ branch, but GitHub which I push to for my remote projects has been creating new projects with a default branch of ‘main’ for some time now.
To move a master branch to main locally, set it as the default branch and then push to GitHub I use the following steps (taken from multiple places but mainly from this article):
Create a new main branch from master locally:
git branch -m master main
Add remote GitHub repo:
git remote add github https://your-repo-url
Pull remote changes from remote main branch
git pull github main
Set upstream branch to track main
git branch --set-upstream-to github/main
Push local to github main
git push github main
If you have changes in the new remote project (like a readme) that don’t exist locally yet and you get the error: “fatal: refusing to merge unrelated histories” then pull with the allow unrelated histories option:
git pull github master --allow-unrelated-histories
Now:’git push’ and you should be good.
For my local development these steps are enough for what I need, but if you have a master in your remote repo too and want to delete it there are additional steps in the article linked above.
CategoriesKev's BlogTagsgit, github, version control
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *
Comment
Name *
Email *
Website
Save my name, email, and website in this browser for the next time I comment.
Notify me of follow-up comments by email.
Notify me of new posts by email.
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Post navigation
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK