How to Rename a Branch in Git (Including master to main)
Renaming a branch in Git is a common task — whether you're fixing a typo, adopting a new naming convention, or migrating from "master" to "main". Here's how to do it locally, on the remote, and across your whole team.
Renaming a Local Branch
To rename the branch you currently have checked out:
$ git branch -m <new-name>
To rename a branch you are NOT currently on:
$ git branch -m <old-name> <new-name>
The Git Cheat Sheet
No need to remember all those commands and parameters: get our popular "Git Cheat Sheet" - for free!
No Command Line Needed
Renaming Branches in Tower
In case you are using the Tower Git client, you can rename both local and remote branches simply from the contextual menu — no need to delete and re-push anything:
Renaming a Remote Branch
Remote branches cannot be renamed directly in Git. In practice, you delete the old one and push the new name:
# Delete the old remote branch:
$ git push origin --delete <old-name>
# Push the renamed local branch to the remote:
$ git push -u origin <new-name>
If the renamed branch had an upstream tracking connection, update it:
$ git branch --set-upstream-to=origin/<new-name>
Teammates who had the old branch checked out will need to run git fetch --prune to remove the stale remote reference, then re-establish tracking:
$ git branch -u origin/<new-name> <new-name>
Renaming "master" to "main"
Many teams are moving away from "master" as the default branch name. Here is how to make that change safely.
Step 1 — Rename locally
$ git branch -m master main
Verify the rename worked:
$ git status
On branch main
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
Step 2 — Push the new branch to the remote
$ git push -u origin main
Step 3 — Change the default branch on your hosting platform
GitHub (and other platforms) won't let you delete a branch that is set as the default or protected. Change the default branch to "main" through your platform's web interface first:
Step 4 — Delete the old "master" branch on the remote
$ git push origin --delete master
No Command Line Needed
Renaming "master" to "main" in Tower
In case you are using the Tower Git client, you can rename branches very easily:
After creating the new "main" branch on the remote, you may need to change the default branch or remove any "protected" status for "master" on your hosting platform before you can delete the old branch.
What Your Teammates Have to Do
Collaborators with local clones of the repository need to update their copies:
# Switch to the "master" branch:
$ git checkout master
# Rename it to "main":
$ git branch -m master main
# Get the latest commits (and branches!) from the remote:
$ git fetch
# Remove the existing tracking connection with "origin/master":
$ git branch --unset-upstream
# Create a new tracking connection with the new "origin/main" branch:
$ git branch -u origin/main
No Command Line Needed
Updating Tracking in Tower
In case you are using the Tower Git client, colleagues can rename their local "master" branch and change the tracking connection from the contextual menu:
Things to Keep in Mind
If you're using CI/CD tools, GitHub Actions, Azure DevOps, Atlassian Bamboo, GitLab CI pipelines, or similar systems, check them carefully after the rename. Any pipeline or webhook that references "origin/master" by name will need to be updated.
Download the Cheat SheetFree
Get 18 of our most popular Cheat Sheets in one handy ZIP!

Thanks! Please Check Your Inbox!
Want to win one of our awesome Tower shirts?
Tell your friends about the package!
