Git
Branch Management
Remote Branches
GitHub
Version Control

Renaming branches remotely in Git

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

Git does not have a single remote "rename branch" command. In practice, renaming a branch remotely means renaming the branch locally, pushing the new name to the remote, and then deleting the old remote branch name.

That sounds simple, but there are a few places where people get tripped up: upstream tracking, default-branch settings, open pull requests, and teammates who still have the old branch checked out locally.

Rename the Local Branch First

If you are currently on the branch you want to rename, use:

bash
git branch -m new-branch-name

If you are renaming a different local branch, specify both names:

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

The -m flag moves the branch name to the new one. At this point the rename exists only in your local repository.

Push the New Branch Name to the Remote

Next, publish the renamed branch and set its upstream tracking branch:

bash
git push origin -u new-branch-name

The -u option matters because it updates the local branch so future git push and git pull commands know which remote branch to use.

If you skip this step, the branch rename appears to work locally, but your default push and pull behavior may still be tied to the old name or may not be configured at all.

Delete the Old Remote Branch Name

Once the new remote branch exists, delete the old one:

bash
git push origin --delete old-branch-name

That removes the stale remote reference. After this point, the remote repository effectively treats the new branch name as the canonical one.

The full sequence usually looks like this:

bash
git branch -m old-branch-name new-branch-name
git push origin -u new-branch-name
git push origin --delete old-branch-name

Special Case: Renaming the Default Branch

If the branch you are renaming is the default branch on GitHub, GitLab, or another hosting platform, there is usually one extra step in the web UI: update the repository's default branch setting.

Most hosting platforms also help with redirects and open pull requests, but you should still verify:

  • the default branch setting,
  • branch protection rules,
  • CI workflows keyed to the old branch name,
  • deployment rules that reference a specific branch.

The Git commands update the repository data. The hosting platform settings may still need manual cleanup.

What Teammates Need to Do

Other developers who already fetched the old branch name need to synchronize their local clone. A common sequence is:

bash
1git fetch origin --prune
2git branch -m old-branch-name new-branch-name
3git branch --unset-upstream
4git branch -u origin/new-branch-name new-branch-name

If they do not have a local branch yet, a fresh checkout is simpler:

bash
git fetch origin --prune
git switch --track origin/new-branch-name

The important detail is --prune, which removes deleted remote-tracking references such as origin/old-branch-name.

Common Pitfalls

  • Renaming only the local branch and forgetting to push the new name.
  • Pushing the new branch but forgetting to delete the old remote branch, which leaves both names active.
  • Forgetting to update the upstream branch after the rename.
  • Renaming the default branch without checking branch protection and CI settings on the hosting platform.
  • Leaving teammates on stale remote-tracking references because nobody pruned the deleted branch.

Summary

  • Remote branch rename is really a push-new and delete-old workflow.
  • Rename locally with git branch -m, then push with git push -u.
  • Delete the old remote name with git push origin --delete.
  • Check hosting-platform settings if the branch is protected or is the default branch.
  • Tell teammates to fetch --prune so their local state matches the remote.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.