⚡DevCheats
Cloudflare Edge
đŸŒŋVCS â€ĸ Git Version ControlVerified for Git 2.20+âąī¸ 45 secondsđŸŽ¯ Intermediate

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 Chen
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-26
bash
git branch -m old-name new-name
git push origin -u new-name
git push origin --delete old-name
Share snippet:𝕏in

📋 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-name
How 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?
← Previous Snippet

Git Undo Last Commit (Keep Changes Staged)

Next Snippet →

Regex for Email Validation in JavaScript

Tags:#git#branch#rename#remote

More Git Version Control Snippets

View full Git Version Control cheatsheet →