How to Rename a Local and Remote Git Branch
Step-by-step commands to rename a branch locally, push the new branch, and reset the upstream tracking.
Alex ChenReviewed by Expert
Staff DevOps & Infrastructure Architect
đ3 min read
âĸđ410 words
âĸđ
Updated 2026-10-26
Verified Command (Single-Click Copy)
Updated: 2026-10-26bash
Press C to copy
git branch -m old-name new-name
git push origin -u new-name
git push origin --delete old-nameđ Prerequisites
State Changing / Caution- âGit CLI
- âRemote write permission on GitHub/GitLab
đĄ Primary Use Cases
Fixing Typos in Branch Names or Ticket Conventions:
Ensures CI/CD webhooks receive the standardized naming format.
# How It Works
`-m` renames the branch locally. Next, push the newly named branch with `-u` (set-upstream). Finally, delete the stale remote branch.
Expected Terminal Output
Branch 'old-name' set up to track remote branch 'new-name' from 'origin'.
To github.com:user/repo.git
- [deleted] old-nameâ ī¸
Gotcha & Common Pitfall
Ensure your teammates are notified before deleting the remote branch to avoid merge conflicts.
âĄ
Performance & Complexity
Time ComplexityO(1)
Space (Memory)O(1)
Mutates OriginalYes (In-Place)
âšī¸ Requires network write permissions to remote repository.
â
Environment & Version Support
Git
2.0+Verified
GitHub / GitLab / Bitbucket
AllVerified
Recommended Tool âĸ Coursera / Git
Master Modern DevOps & CI/CD
Accelerate your career with industry-recognized Git, GitHub Actions, and Kubernetes certifications.
đ People Also Ask (Related Quick Answers)
How to delete a local branch in Git?
git branch -d branch-nameHow to list all remote branches?
git branch -r?
Frequently Asked Questions about How to Rename a Local and Remote Git Branch
How do I rename the branch I am currently on?âŧ
Simply run "git branch -m new-name" without typing the old branch name.
đŦWas this snippet helpful for your problem?
Thank you for your feedback! It helps improve this guide.
â Previous Snippet
Git Undo Last Commit (Keep Changes Staged)
Next Snippet âRegex for Email Validation in JavaScript
Tags:#git#branch#rename#remote