Branches & Tags

How to Rename a Local and Remote Git Branch

Rename your current local branch and update the upstream remote tracking branch on GitHub or GitLab.

Instant 1-Line Solution
Safe CommandBeginner
git branch -m <old-name> <new-name>
When to use this scenario:You made a typo in a feature branch name or want to change your branch naming convention to match Jira/ticket standards.

Step-by-Step Execution Guide

1Rename local branch while on it
git branch -m new-branch-name

Renames your currently checked-out branch to the new name.

2Delete old branch on remote
git push origin --delete old-branch-name

Removes the old branch from GitHub/GitLab to avoid stale branch clutter.

3Push new branch and set upstream tracking
git push origin -u new-branch-name

Pushes the renamed branch and links your local branch to track origin/new-branch-name.

Critical Pitfalls & Precautions

  • β€’If you have open Pull Requests on GitHub for the old branch, changing the branch name will automatically close or update the PR branch target.
Frequently Asked Questions

Rename Branch - Frequently Asked Questions

Common questions about safe rollback, remote history implications, and troubleshooting.

Run "git branch -m master main", push with "git push -u origin main", then change the default branch setting in GitHub Repository Settings.