I just renamed my local branch using
git branch -m oldname newname
but this only renames the local version of the branch. How can I rename
Simple as that. In order to rename a Git branch locally and remotely use this snippet (tested and works like a charm):
git branch -m
git push origin :
git push --set-upstream origin
Explanation:
Git reference: 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.
Git reference: git push origin :experimental Find a ref that matches experimental in the origin repository (e.g. refs/heads/experimental), and delete it.
Git reference: --set-upstream For every branch that is up to date or successfully pushed, add upstream (tracking) reference, used by argument-less git-pull[1] and other commands. For more information, see branch.
.merge in git-config[1].