5 simple steps that I tested and used to make the change in under 1 minute.
-
Move the
master
branch tomain
git branch --move master main
-
Push
main
to remote repogit push --set-upstream origin main
-
Point
HEAD
tomain
branchgit symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
-
Change default branch to
main
on GitHub- Navigate in your browser to your GitHub repository.
- From the left rail, click Settings -> Branches and change the default branch to
main
-
Delete
master
branch on the remote repogit push origin --delete master
After you rename a branch in a repository on GitHub, any collaborator with a local clone of the repository will need to update the clone.
From the local clone of the repository on a computer, run the following commands to update the name of the default branch.
git branch -m OLD-BRANCH-NAME NEW-BRANCH-NAME
git fetch origin
git branch -u origin/NEW-BRANCH-NAME NEW-BRANCH-NAME
git remote set-head origin -a
Optionally, run the following command to remove tracking references to the old branch name.
git remote prune origin
Source: GitHub: Updating a local clone after a branch name changes
To initialize a new Git repository
and set the default branch to main
:
git init --initial-branch=main