in Coding, DevOps, git, Uncategorized

How to Rename a local and remote branch in git

Just in case you pushed a wrongly named branch. wink

1. Rename your local branch.
Get to the branch you want to rename:

1
git branch -m new-name

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

1
git push origin :old-name new-name

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

1
git push origin -u new-name

Note: Make sure you run command git status and check that newly created branch is pointing to its own ref and not older one. If you find the reference to older branch, you need to unset the upstream using

git branch --unset-upstream