Ad space (banner)
🌿Git Lessons
Lesson 30 / 59

Renaming a Branch with git branch -m

This lesson covers renaming a branch with git branch -m. It's for anyone searching "git branch -m usage."

git branch -m renames an existing branch. Use it when you've mistyped a branch name, or want to switch to a clearer one.

In Try It, run git branch -m feature3 feature-renamed. The branch named feature3 is renamed to feature-renamed.

A common early mistake is missing that the argument syntax differs depending on whether you're renaming the branch you're currently on versus a different one — for your current branch, give just the new name; for another branch, give both the old name and the new one. In real teams, renaming a branch that's already been pushed to the remote requires updating the remote side too, not just locally, so keep that in mind.

Git
Try it (type this into the pseudo terminal)
git branch -m feature3 feature-renamed

🧑‍💻 You can type this command into the Git pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)