Knowledge

How to rename a Git branch (local and remote)

#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 on June 23, 2026 · 1 minute read

  1. Rename the branch you are on
  2. Rename a different branch
  3. Push the rename to the remote
  4. Renaming the default branch

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

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

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.

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.

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!

Related articles

Install PHP memcached extension on macOS

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.

Read more →

How to delete a local (and remote) Git branch

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.

Read more →