---
title: "How do I rename a Git branch locally and on the remote?"
description: "Rename a branch with git branch -m, push the new name, delete the old one on the remote and fix the upstream, so you and your team end up on the same branch."
url: https://www.danny.engineering/answer/git/how-do-i-rename-a-git-branch-locally-and-on-the-remote
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:57:00.000Z
tags: ["Git"]
---

# How do I rename a Git branch locally and on the remote?

## The short answer


Git has no single command that renames a branch everywhere. Rename it locally with `git branch -m`, push the new name and set it as the upstream, then delete the old name on the remote.


```bash
git branch -m old-name new-name          # rename locally
git push -u origin new-name              # push and track the new name
git push origin --delete old-name        # remove the old name from the remote
```


## Why it happens


A branch is just a named pointer to a commit. Your local branch and the branch on the remote are two separate pointers that happen to share a name, and your local branch remembers which remote branch it tracks (its upstream).


`git branch -m` only renames your local pointer. The remote still has the old name, and your local branch still tracks `origin/old-name`. That is why you need the extra push and delete steps, and why teammates have to update their own clones.


## How to fix it


### Rename the branch locally


If you are on the branch you want to rename, give only the new name:


```bash
git switch feature/login
git branch -m feature/sign-in
```


From any other branch, give both names:


```bash
git branch -m feature/login feature/sign-in
```


If a branch with the new name already exists, Git refuses. `-M` forces the rename and overwrites the existing branch, so check first with `git branch --list`. `-M` is also the flag to use for a change that only alters letter case, such as `Feature` to `feature`, on case-insensitive file systems like the macOS default.


### Update the remote


Push the renamed branch and set its upstream in one go:


```bash
git push -u origin feature/sign-in
```


Then delete the old branch on the remote:


```bash
git push origin --delete feature/login
```


Check the result with `git branch -vv`, which shows each local branch and the remote branch it tracks.


### Use your hosting service for shared branches


For a branch other people use, especially a default branch such as `master` to `main`, the web interface of services like GitHub and GitLab can rename it for you. The service then updates things that point at the branch, such as open pull requests and branch protection rules, which a manual delete and push does not. After renaming there, update your local clone as below.


### Update a teammate's clone


Anyone who already has the branch checked out needs to rename theirs and point it at the new upstream:


```bash
git fetch origin --prune                       # get the new name, drop the old one
git branch -m feature/login feature/sign-in
git branch -u origin/feature/sign-in feature/sign-in
```


If the renamed branch was the remote's default branch, also refresh the remembered default:


```bash
git remote set-head origin --auto
```


## Common pitfalls

- Renaming locally and stopping there. The next `git push` either fails or goes to the old remote name, because the upstream still points at it.
- Deleting the old remote branch while pull requests use it. Many services close or orphan those pull requests. Rename through the web interface, or retarget them first.
- Forgetting CI configuration, deploy settings or branch protection rules that name the old branch.
- Using `-M` without checking for an existing branch with the new name. That branch is replaced.
- Expecting `git fetch` alone to remove the old remote-tracking branch. Add `--prune`, or set `git config --global fetch.prune true`.

## Related reading

- [Git documentation: git branch](https://git-scm.com/docs/git-branch)
- [Git documentation: git push](https://git-scm.com/docs/git-push)
