I have 4 braches like master -> origin/regacy, FeatureA -> origin/FeatureA.
As you can see above, I typed a wrong name.
So I want to rename a remote branch name ( origin/regacy => origin/legacy or origin/master)
I try to command below.
git remote rename regacy legacy
But git console retured error msg to me.
error : Could not rename config section 'remote.regacy' to
'remote.legacy'
How can i solve this problem?
解决方案
You can't directly rename a remote branch.
You have to delete it and then re-push it.
Renaming a branch
# rename the local branch to the new name
git branch -m
# delete the old branch on remote - where is eg. origin
git push --delete old_name
# push the new branch to remote
git push new_name
Important note :
When you use the git branch -m (move), git is also updating your tracking branch with the new name.
git remote rename regacy legacy
git remote rename is trying to update your remote section in your config file. It will rename the remote with the given name to the new name, but in your case it did not find any, so the renaming failed.
But it will not do what you think, it will rename your local config remote name and not the remote branch.
Note
Git servers might allow you to rename git branch using the web interface or external programs (like Sourctree etc) but you have to keep in mind that in git all the work is done locally so its recommended to use the above commands to the work.