How to Rename a Branch in Git: Step-by-Step Guide

Sometimes you realize your Git branch name doesn’t quite fit your work anymore — maybe it’s a typo, or you want a clearer description. Git makes it easy to rename branches both locally and remotely.

This guide will show you how to rename a Git branch safely and keep everything in sync.


🧠 Why Rename a Branch?

  • Fix typos or unclear names.
  • Follow naming conventions.
  • Reflect new scope or features.

✅ Step 1: Rename a Local Branch

If you’re currently on the branch you want to rename:

git branch -m new-branch-name

If you’re on a different branch:

git branch -m old-branch-name new-branch-name

✅ Step 2: Update Remote Branch (Optional)

If the branch was already pushed to a remote like GitHub, update the remote branch name:

Delete the old branch on remote:

git push origin --delete old-branch-name

Push the new branch and set upstream:

git push origin -u new-branch-name

✅ Step 3: Inform Your Team

Renaming remote branches can disrupt others if they’re using the old branch. Notify your team to update their local copies:

git fetch origin
git checkout new-branch-name

🧩 Summary of Commands

TaskCommand
Rename current branch locallygit branch -m new-branch-name
Rename different local branchgit branch -m old-branch-name new-name
Delete old remote branchgit push origin --delete old-branch-name
Push new branch and set upstreamgit push origin -u new-branch-name

📌 Final Tips

  • Always check which branch you’re on with git branch.
  • Renaming branches won’t affect your commit history.
  • Coordinate with your team when renaming remote branches.
Sharing Is Caring:

Leave a Comment