When working with branches you can get in situation where branch names are not correct. It may be that you need to follow specific naming conventions or there has just slipped in a typo in your branch name. With these steps you can easy rename your code branch and clean up after yourself even if you incorrect branch was push to the remote repository.

  1. Rename your local branch.

    If you are on the branch you want to rename:

    git branch -m new-name

    If you are on a different branch:

    git branch -m old-name new-name

  2. Delete the old-name remote branch and push the new-name local branch.

    git push origin :old-name new-name

  3. Reset the upstream branch for the new-name local branch. Switch to the branch and then:

    git push origin -u new-name