🌿 BranchingCommonly used

How to rename a branch in Git

Rename a local or remote branch.

Rename current branch
git branch -m new-name

Renames the branch you are currently on.

When to use: You are on the branch you want to rename.

Rename any branch
git branch -m old-name new-name

Renames a branch by specifying both old and new names.

When to use: Renaming a branch you are not currently on.

Rename and update remote
git branch -m old-name new-name
git push origin --delete old-name
git push -u origin new-name

Renames locally, deletes the old remote branch, and pushes the renamed branch.

When to use: When the branch has already been pushed to remote.

Team members will need to update their local tracking: git fetch --prune && git branch -u origin/new-name new-name

← Back to Git Reference