Rename a Git Branch |Video upload date:  · Duration: PT42S  · Language: EN

Quick guide to rename a Git branch locally and update the remote with safe commands and practical tips.

If you want to rename a Git branch and avoid a tiny office revolt follow these tidy steps. This guide shows how to rename a branch locally push the new name set tracking and remove the old remote reference so history stays neat and your CI does not throw a tantrum.

Quick checklist before you start

Branch renames are low risk but do a quick scan first. Make sure you have committed or stashed changes and that no one else is actively pushing to the branch. If there is an open pull request know how your hosting service handles renamed branches.

Step 1 Rename the branch locally

If you are on the branch you want to rename use this neat and short command. It renames your current branch in place without rewriting history.

git branch -m new-name

If you are not checked out on the branch give both names. This lets you rename from anywhere in the repo.

git branch -m old-name new-name

Step 2 Push the new name to the remote

Send the freshly named branch up to the remote so the remote repo has the new label. This does not remove the old name remotely yet.

git push origin new-name

Step 3 Set upstream tracking for the new branch

Tell your local branch which remote branch to follow so git push and git pull behave like adults.

git push --set-upstream origin new-name

Step 4 Remove the old branch from the remote

Now that the new name is on the remote remove the outdated label so other developers do not get confused by ghost branches.

git push --delete origin old-name

Step 5 Clean up and let people know

Prune stale references in your local copy so git fetch shows a tidy view. Then send a brief message in your team channel so open pull requests and CI pipelines do not surprise anyone.

git fetch -p

If there is a pull request

Many hosting services let you update the PR branch to the new name or they will follow the rename automatically. If your provider does not do that manually reassign the PR branch or leave a note so reviewers know what happened. Do not close the PR unless you must.

Extra tips for civilized branching

  • Prefer descriptive branch names that survive a rename without sounding like a snack attack.
  • If multiple people use the branch coordinate the change in a team chat to avoid surprises.
  • Update CI and deploy configs if they reference the old name directly.

Follow this order rename locally push the new name set tracking and then delete the old remote name. A quick fetch prune keeps local repos clean and a polite message prevents grown adults from panicking over a new branch name.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.