Rename local and remote git branches
1 min readMay 19, 2019
So you have git branch
’ed the new branch, did tons of great coding, only to realize that the branch name does not reflect your amazing work and there’s inevitable need for renaming. On top of everything, you have already pushed it to remote. No problem, let’s rename your local and remote branches in 3 super easy steps:
- Rename local branch.
// Are you on the branch you want to rename?YES: git branch -m new-branch-nameNO: git branch -m old-branch-name new-branch-name
2. Rename remote branch (delete old and push the new one).
git push origin :old-branch-name new-branch-name
3. Reset the upstream.
// You have to be on the newly (re)named branch.git push origin -u new-branch-name
And this is it. Life goes on.