Some Guy
Some Guy

Reputation: 13568

Use master instead of main for git

I just made a new git repo and pushed it to github, but noticed my git commands aren't working because git show-ref shows only 'main' instead of 'master'. I want to use master since that's what all my commands and tools expect. How can I change it to use 'master' instead of 'main'?

Upvotes: 11

Views: 8619

Answers (1)

prahasanam_boi
prahasanam_boi

Reputation: 896

Please try the following steps:

step 1) check your local branch also named 'main'. You can check that in your local repository by:

git branch

If it is 'main', after making both remote and local up-to-date, rename your local 'main' branch to 'master' and push the branch to remote. If the local repo is already 'master', skip renaming the branch and directly push. Make sure no 'master' branch exist currently in the remote repo. If yes, delete or rename that before pushing.

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

step 2) Log in to your remote repo, and change the default branch to master. You can refer to this, in case you have any trouble doing that:

https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-branches-in-your-repository/changing-the-default-branch

Step 3) Delete the 'main' branch in the remote repo. You can do it from the browser.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-and-deleting-branches-within-your-repository

Or you can do the following commands:

git push origin --delete main
git remote set-head origin -a

I think this will help. Also, requesting you to check why Github has decided to change from 'master' to 'main', if possible.

Reference : https://dev.to/rhymu/git-renaming-the-master-branch-137b

Upvotes: 15

Related Questions