How to Rename a Git Branch

Rename a local branch with git branch -m. If the branch was already pushed, publish the new name and coordinate the change with anyone else using the old remote branch.

Practice Git workflows →

Rename the branch you are currently on

Check your current branch, then rename it:

git branch --show-current
git branch -m new-branch-name

Replace new-branch-name with the name you want. The -m option renames the current local branch and keeps its commit history.

Rename a different local branch

To rename a branch without switching to it, provide both the existing and new names:

git branch -m old-branch-name new-branch-name

If a local branch already uses the new name, Git will not overwrite it with -m. Check your branches with git branch and choose an available name. The -M option can force an overwrite, but use it only if you intentionally want to replace that local branch reference.

Push a renamed branch to the remote

Renaming a branch locally does not rename its remote counterpart. Push the new branch and set it as the upstream:

git push -u origin new-branch-name

Replace origin if your remote has a different name. Confirm the new branch appears on the remote before taking any action on the old one.

What to do with the old remote branch

If the old remote branch is no longer needed, and you have confirmed the replacement is published, it can be deleted with:

git push origin --delete old-branch-name

Deleting the remote branch affects everyone who uses it. Coordinate with collaborators first, and check open pull requests, automation, and branch protections. If other people have the old branch checked out, they may need to fetch and switch to the new name.

Update your local remote-tracking branches

After the remote branch is renamed or deleted, refresh your local view of remote branches:

git fetch origin --prune
git branch -vv

--prune removes stale remote-tracking references for branches that no longer exist on the remote. It does not delete local branches.

Git branch rename FAQ

Does renaming a branch change its commits?

No. Renaming changes the branch reference, not the commits it points to.

Does git branch -m rename the branch on GitHub?

No. It renames only your local branch. Push the new name and handle the old remote branch separately according to your team’s workflow.

Learn Git Faster by Practicing

Reading is just the first step. Real learning happens when you practice.

Start Learning Git →