How do I rename a branch in Git?
Renaming a branch in Git is a two-part operation: updating the name locally and then reflecting that change on the remote. Neither step touches your commit history — you are only changing a label.
Rename the current branch
If you are already on the branch you want to rename, use the -m flag (short for "move") with git branch:
git branch -m new-name
Rename a different branch
If you want to rename a branch you are not currently on, pass both the old and new names:
git branch -m old-name new-name
For more on how branches work, see our guide on branching and merging.
Update the remote
Renaming locally does not affect the remote. You will need to push the new branch name and delete the old one.
Push the renamed branch and set tracking
git push origin -u new-name
The -u flag sets the upstream tracking reference so future git push and git pull commands work without specifying the remote and branch name.
Delete the old remote branch
git push origin --delete old-name
If other team members have the old branch checked out, they can run:
git fetch --all --prune
git branch --set-upstream-to=origin/new-name new-name
The --prune flag removes stale remote-tracking references that no longer exist on the remote.
Summary
| Step | Command |
|---|---|
| Rename current branch | git branch -m new-name |
| Rename a different branch | git branch -m old-name new-name |
| Push renamed branch | git push origin -u new-name |
| Delete old remote branch | git push origin --delete old-name |
If you are renaming the default branch, your hosting provider (GitHub, GitLab, Bitbucket) has settings to update the default branch reference through their web interface — this avoids confusion for contributors cloning the repository fresh.
Ready to streamline your Git workflow? DeployHQ deploys your code automatically whenever you push to your repository.