Git Cheat Sheet · Branches
Rename a branch
git branch -m <old> <new>
git branch -m <old> <new> renames a local branch; its commits do not change. On the current branch, git branch -m <new> is enough. The remote branch keeps its old name until you republish it.
What it does
Changes the name of a local branch without changing its commits.
A use case
Your branch is called "test" and you want a name that describes the work before publishing it.
On the command line
git branch -m <new>- Renames the current branch.
git branch -m <old> <new>- Renames another branch.
git push -u origin <new>- Publishes the branch under its new name.
git push origin --delete <old>- Deletes the old name on the remote.
In Merathon
- Right-click the branch in "Local" → "Rename…".
Frequently asked questions
How do I rename master to main?
git branch -m master main, git push -u origin main, change the default branch in the forge's settings, then git push origin --delete master.
Does renaming a branch break an open pull request?
On GitHub, rename the branch from the repository's web interface instead: pull requests follow. Deleting the old remote branch closes the pull requests that start from it.