rikosjett


Rename git master branch to main

Published at 1 April 2021

#git

How to rename old repository master branch to main.

Rename local branch

SHELL
$ git branch -m master main

Push new main branch to origin

SHELL
$ git push -u origin main

Delete old master branch

If old master isn’t the defaultbranch on the remote

SHELL
$ git push origin --delete master

If 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:

SHELL
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'