How to rename a Git branch (local and remote) - Rocketeers

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com) 

 On this page

 Knowledge
---------

How to rename a Git branch (local and remote)
=============================================

### [\#Development](https://rocketee.rs/index.php/development)

Renaming a branch locally is one command. The part people miss is updating the remote: Git cannot rename a remote branch directly, so you push the new name and delete the old one.

 Published by [Mark van Eijk](https://rocketee.rs/index.php/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [Rename the branch you are on](#content-rename-the-branch-you-are-on)
2. [Rename a different branch](#content-rename-a-different-branch)
3. [Push the rename to the remote](#content-push-the-rename-to-the-remote)
4. [Renaming the default branch](#content-renaming-the-default-branch)

[\#](#content-rename-the-branch-you-are-on "Permalink")Rename the branch you are on
-----------------------------------------------------------------------------------

The `-m` (move) flag renames a branch. To rename the branch you currently have checked out, you only need the new name:

 ```
git branch -m new-name

```

[\#](#content-rename-a-different-branch "Permalink")Rename a different branch
-----------------------------------------------------------------------------

To rename a branch without checking it out first, give both the old and new names:

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

```

[\#](#content-push-the-rename-to-the-remote "Permalink")Push the rename to the remote
-------------------------------------------------------------------------------------

A remote branch cannot be renamed in place. The workflow is: push the new name, then delete the old one.

First push the renamed branch and set it as the upstream:

 ```
git push origin -u new-name

```

Then delete the old branch from the remote:

 ```
git push origin --delete old-name

```

If other people work on this branch, tell them: their local clones still track the old name and will need `git fetch --prune` to clean it up.

[\#](#content-renaming-the-default-branch "Permalink")Renaming the default branch
---------------------------------------------------------------------------------

The same steps apply to a default branch (for example renaming `master` to `main`), but you also have to update the default on your hosting platform (GitHub, GitLab) in the repository settings, and update any branch protection rules or CI configuration that referenced the old name.

To delete a branch entirely rather than rename it, see [How to delete a local (and remote) Git branch](/git-delete-local-branch).

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Development](https://rocketee.rs/index.php/development)

- [Install PHP memcached extension on macOS](https://rocketee.rs/index.php/install-php-memcached-extension-on-macos)
- [How to delete a local (and remote) Git branch](https://rocketee.rs/index.php/git-delete-local-branch)
- [Fix: Cannot connect to the Docker daemon at unix:///var/run/docker.sock](https://rocketee.rs/index.php/cannot-connect-to-docker-daemon)
- [git stash pop vs apply: save and restore changes](https://rocketee.rs/index.php/git-stash-pop)
- [How to clean up Docker with prune (images, volumes, system)](https://rocketee.rs/index.php/docker-prune)
- [What port does SSH use (and how to change it)](https://rocketee.rs/index.php/ssh-port)

 [View all 12 articles →](https://rocketee.rs/index.php/development)
