Rename local branch
To rename a local branch in git
- Move on the branch you want to rename
git checkout -b feature/wrong-name
- Rename it locally
git branch -m feature/new-awesome-name
⚡️ Bonus tip
If you have ohmyzsh installed, you can use its shortcut
gbm
.
Rename remote branch
To rename a remote branch is quite longer:
- Unset the upstream branch to unlink local and remote branch
git branch --unset-upstream
Note: if you followed the previous step, you don't have to delete local branch because you have already renamed it!
- Update the upstream branch to the new one and push it
git push --set-upstream origin feature/new-awesome-name
- Delete remote branch
git push origin --delete feature/wrong-name
Top comments (0)