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
Next, you'll add the main branch to the remote.
You can also set the main branch as the default branch.
Then delete the master branch in the remote.
git push origin :master
Finally, the local main branch follows the remote main branch.
git push --set-upstream origin main
References
rename git branch locally and remotely
Git Set Upstream | Learn Version Control with Git
Top comments (0)