DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 966,155 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Rename the branch from "master" to "main" in an existing GitHub repository
welchi
welchi

Posted on

Rename the branch from "master" to "main" in an existing GitHub repository

What I want to do

Sometimes I want to change the name of a branch, both locally and remotely.
For example, I may want to change the name of the branch from master to main.
This article will show you how to do that.

Procedure

First, locally, rename the branch from master to main.

git branch -m master main
Enter fullscreen mode Exit fullscreen mode

Next, you'll add the main branch to the remote.
γ‚Ήγ‚―γƒͺγƒΌγƒ³γ‚·γƒ§γƒƒγƒˆ_2020-10-13_23_48_51eng

You can also set the main branch as the default branch.

γ‚Ήγ‚―γƒͺγƒΌγƒ³γ‚·γƒ§γƒƒγƒˆ_2020-10-13_23_51_133eng

Then delete the master branch in the remote.

git push origin :master
Enter fullscreen mode Exit fullscreen mode

Finally, the local main branch follows the remote main branch.

git push --set-upstream origin main
Enter fullscreen mode Exit fullscreen mode

References

rename git branch locally and remotely
Git Set Upstream | Learn Version Control with Git

Top comments (0)

🌚 Life is too short to browse without dark mode