How to rename main branch to master on a Github repository

Using the -m option (move/rename) instead of -M with the name of the branch you’re renaming from, here main, will work. Then you can push your renamed branch and maintain your reflog as well.

git branch -m main master
git push -u origin master

I also wrote a blog post with more details which can in case the repo was cloned by someone else before renaming the branch. You can check it out here.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)