Patricio Treviño

Patricio Treviño

Husband . Father . Developer

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

  1. 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>
    view raw 1.sh hosted with ❤ by GitHub
  2. Replacing the old remote branch with the new local branch.
    git push origin :<old-name> <new-name>
    view raw 2.sh hosted with ❤ by GitHub
  3. Resetting the upstream branch in the new local branch.
    git push origin -u <new-name>
    view raw 3.sh hosted with ❤ by GitHub