DEV Community

Giulia Chiola
Giulia Chiola

Posted on • Originally published at giuliachiola.dev

How to rename a git branch

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

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay