How to Rename a Git Branch: Local and Remote

By 

Updated on

3 min read

Renaming a local and remote Git branch with git branch -m

Git does not provide a direct command to rename a remote branch. The standard approach is to rename the local branch, push it under the new name, and delete the old remote branch.

This guide explains how to rename a local and remote Git branch step by step.

Quick Reference

TaskCommand
Rename the current local branchgit branch -m <new_name>
Switch to branch, then renamegit switch <old_name>git branch -m <new_name>
Push new branch and set upstreamgit push origin -u <new_name>
Delete old remote branchgit push origin --delete <old_name>
Update local tracking after renamegit fetch --prune

For a printable quick reference, see the Git cheatsheet .

Rename the Local Branch

If you are already on the branch you want to rename, run:

Terminal
git branch -m <new_name>

If you are on a different branch, switch to the target branch first:

Terminal
git switch <old_name>

Then rename it:

Terminal
git branch -m <new_name>

At this point, the local branch has been renamed. If you have not yet pushed the branch to a remote repository , you are done.

Rename the Remote Branch

Renaming a remote branch requires pushing the local branch under the new name and deleting the old remote branch.

  1. Push the <new_name> branch to the remote and set it as the upstream:

    Terminal
    git push origin -u <new_name>
  2. Delete the <old_name> branch from the remote:

    Terminal
    git push origin --delete <old_name>

The remote branch is now available under the new name.

Update Collaborators

After renaming a remote branch, team members who had the old branch checked out need to update their local tracking references. They should run the following commands:

Terminal
git fetch --prune
git branch -m <old_name> <new_name>
git branch --set-upstream-to=origin/<new_name> <new_name>

git fetch --prune removes the stale reference to the old remote branch. git branch -m renames the local branch, and git branch --set-upstream-to points the local <new_name> branch at the new remote name.

FAQ

Can I rename the branch I am currently on?
Yes. Running git branch -m <new_name> without switching away first renames the branch you are currently on. You only need to git checkout <old_name> first if you are on a different branch.

Do I need to update anything after renaming the remote branch?
Yes, if other people have the old branch checked out. They need to run git fetch --prune, rename their local branch with git branch -m <old_name> <new_name>, and then run git branch --set-upstream-to origin/<new_name> <new_name> to update their local tracking reference.

What if I only want to rename the branch locally?
Run git branch -m <old_name> <new_name> (or switch to the branch first and run git branch -m <new_name>). As long as you do not push anything, the remote branch is unaffected.

What is the difference between git branch -m and git branch -M?
-m refuses to rename if a branch with the new name already exists. -M forces the rename and overwrites the existing branch. Use -m unless you intentionally want to overwrite.

What if I made a typo in a commit message instead of the branch name?
Use git commit --amend to edit the most recent commit message, or git rebase -i to reword older commits.

Conclusion

To rename a Git branch, rename it locally with git branch -m, push the new name to the remote with git push origin -u <new_name>, and remove the old remote branch with git push origin --delete <old_name>.

For more Git branch operations, see How to Create and List Git Branches and How to Delete a Local and Remote Git Branch . For a quick command overview, see the Git cheatsheet .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page