Cheat Sheets · Git Cheat Sheet · Git Rename Local Branch — Safely & Quickly
Git Rename Local Branch — Safely & Quickly
git branch -m <new-name>Rename the branch you are currently on
git branch -m <old-name> <new-name>Rename any branch without switching to it first
git branch -M <new-name>Force rename — even if new-name already exists
Rename commands
| Command | Effect |
|---|---|
git branch -m <new-name> | Rename the branch you are currently on |
git branch -m <old-name> <new-name> | Rename any branch without switching to it first |
git branch -M <new-name> | Force rename — even if new-name already exists |
Renaming a local branch changes its pointer in .git/refs/heads. It is safe, instant, and does not touch your commit history.
Related Git recipes
FAQ
Does renaming a local branch affect the remote?
No. Renaming locally only changes your local ref. To update GitHub/GitLab, push the new name and delete the old remote branch.
What if -m fails with "already exists"?
If you are certain you want to overwrite an existing branch, use capital -M.
How do I verify the rename worked?
Run git branch --show-current to inspect your active branch name.
Stop memorizing — build it interactively
Build branch commands in the Git BuilderFull reference: Git Cheat Sheet