DEV Community

loading...

How to rename a git branch

Giulia Chiola
Front-end Developer. 👾 Media engineer. ⚡ Facing life one bug at a time. 🔥 Easily bribed with chocolate. 🍫 she/her.
Originally published at giuliachiola.dev ・1 min read

Rename local branch

To rename a local branch in git

  • Move on the branch you want to rename
git checkout -b feature/wrong-name
Enter fullscreen mode Exit fullscreen mode
  • Rename it locally
git branch -m feature/new-awesome-name
Enter fullscreen mode Exit fullscreen mode

⚡️ 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
  • Delete remote branch
git push origin --delete feature/wrong-name
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

Forem Open with the Forem app