A branch name can become wrong after the task changes scope, a typo reaches review, or a team naming convention changes. Rename the local branch before pushing, reviewing, or merging so later commands and pull requests refer to the branch by the intended name.
git branch -m changes the local branch reference name. It keeps the commits, working tree files, branch configuration, and branch reflog attached to the renamed branch instead of rewriting history.
Use these steps when the branch to rename is local and the terminal is already inside the repository. A remote branch with the old name is a separate reference, so rename the local branch first and coordinate any push, upstream, or remote deletion after the local name is correct.
Related: Create and switch to a Git branch
Related: Set upstream tracking for a Git branch
Related: Delete a remote Git branch
Related: Run a default branch rename in Git
$ git branch --show-current feature/login-form
If another branch is active, switch to the branch first with git switch feature/login-form or rename the inactive branch with git branch -m feature/login-form feature/docs.
$ git log --oneline --decorate -1 02bbaa2 (HEAD -> feature/login-form) Update login notes
The short commit hash is the value to compare after the rename. It should stay the same when only the branch name changes.
$ git branch -m feature/docs
Git normally prints no output when the rename succeeds. Use git branch -M feature/docs only when feature/docs already exists locally and replacing that name is intentional.
$ git branch --show-current feature/docs
$ git branch * feature/docs main
$ git log --oneline --decorate -1 02bbaa2 (HEAD -> feature/docs) Update login notes
The commit hash should match the pre-rename check, while the decoration should show HEAD -> feature/docs.
$ git status -sb ## feature/docs
If status shows an upstream branch with the old name, set the new upstream after pushing the renamed branch. Renaming a local branch does not rename an existing remote branch.