Rename a git branch
There are only two hard things in Computer Science: cache invalidation and naming things.
-- Phil Karlton
As Phil Karlton says, naming things has, is, and will always be hard. This is especially true when you are the new guy in the office and you are still trying to memorize the thousands and thousands of code standards/conventions the new team has.
Fortunately for the new guy, almost everything has a fix and when it comes down to branch naming conventions it is as easy as following the steps described in this guide.
Steps
- Renaming the local branch
# if you are on the same branch git branch -m <new-name> # if you are on a different branch git branch -m <old-name> <new-name> - Replacing the old remote branch with the new local branch.
git push origin :<old-name> <new-name> - Resetting the upstream branch in the new local branch.
git push origin -u <new-name>