Rename: master -> main
I renamed default branch of all my existing repositories in Github and Gitea several months ago.
Here shows how I did it.
Tutorial
1. Rename brnach
Clone repository.
$ git clone <repo>
$ cd <repo>
Rename it.
$ git branch -m master main
Well, git branch
's official documentation says:
With a
-m
or-M
option, will be renamed to . If had a corresponding reflog, it is renamed to match , and a reflog entry is created to remember the branch renaming. If exists, -M must be used to force the rename to happen.
Optionally, it's able to check the result with git status
.
$ git status
On branch main
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
Push the change.
$ git push -u origin main
Done.
2. Configure hosting service
With Web browser, visit github or gitea, and show settings page.
Then, switch "Default branch" from master to main.
3. Delete old branch
Delete old branch if it has become unnecessary.
$ git push origin --delete master
Top comments (0)