Scenario: old repo, checked out locally. You discover that the default branch is master
.
Follow these instructions to rename the branch - locally and on your remote copies.
- Make sure you are on
master
git checkout master
- Rename the current local branch
git branch -m master main
- Check if the rename worked
git status
It should specify that it's currently on branch main and it's set to track 'origin/master'. 4. Remove the upstream reference
git branch --unset-upstream
- Push to remote, this will create a new
main
on remote
git push -u origin main
It should confirm branch 'main' set up to track 'origin/main'
6. To delete master from remote, you will have to first set the newly made main
as your new default (if you're using GitHub).
Go to Settings -> General -> Default Branch -> Switch and select main
and confirm changes.
7. Delete remote master
git push origin :master