Rename git master branch to main
Published at
This TIL is more than a year old. Some details may have changed.
How to rename old repository master branch to main.
Rename local branch
$ git branch -m master mainPush new main branch to origin
$ git push -u origin mainDelete old master branch
If old master isn't the defaultbranch on the remote
$ git push origin --delete masterIf you get an error, this step needs to be done manually on the remote, as main needs to be set as defaultbefore deleting the old master.
Error message:
To github.com:<account>/<repo name>.git
! [remote rejected] master (refusing to delete the current branch: refs/heads/master)
error: failed to push some refs to 'github.com:<account>/<repo name>.git'