On This Page
How to Rename a Git Branch (Local & Remote)
Quick Answer: To rename your current local branch, run git branch -m <new-name>. To rename a branch while on a different branch, run git branch -m <old-name> <new-name>. If the branch is already pushed to GitHub or a remote server, delete the old remote branch and push the new one with git push origin -u <new-name>.
Quick Reference Cheat Sheet
| Task | Command |
|---|---|
| Rename current branch | git branch -m <new-name> |
| Rename another local branch | git branch -m <old-name> <new-name> |
| Push new branch to remote | git push origin -u <new-name> |
| Delete old remote branch | git push origin --delete <old-name> |
| Rename default master to main | git branch -m master main |
Step-by-Step: Renaming a Local Branch
Option A: If you are currently on the branch
# 1. Ensure you are on the branch you want to rename
$ git checkout old-name
# 2. Rename the branch to new-name
$ git branch -m new-name
Option B: If you are on a different branch
# Rename old-name to new-name without switching
$ git branch -m old-name new-name
Step-by-Step: Updating the Remote Branch (GitHub / GitLab)
Renaming a local branch does not automatically update the remote repository. Follow these 3 steps to update the remote server:
# 1. Push the newly named local branch and set upstream tracking
$ git push origin -u new-name
# 2. Delete the old branch from the remote server
$ git push origin --delete old-name
If collaborators are working on the project, tell them to run:
$ git fetch origin
$ git remote prune origin
What Happens Under the Hood?
In Git, a branch is not a folder or container — it is simply a 41-byte text file inside .git/refs/heads/ containing a 40-character SHA-1 commit hash.
When you run git branch -m old-name new-name, Git simply renames the text file .git/refs/heads/old-name to .git/refs/heads/new-name and updates .git/HEAD if you were currently on that branch. Learn more about ref pointers in our /git-refs and /git-branch tutorials.