Interview Q&A / Git & GitHub

BeginnerQuick answer1 min readUpdated 3 Oct 2026

How do you rename a Git branch, including one already pushed?

SHORT ANSWER

Locally use git branch -m old new. For a pushed branch, push the new name, set its upstream, and delete the old name on the remote. Tell teammates, since their copies still track the old name.

Explain it simply

Renaming a branch is like renaming a WhatsApp group: easy for you, but everyone else still has the old name in their list until they update.

The local rename is one command. The remote has no rename operation, so you publish the new branch and delete the old one. Pull request pages linked to the old branch may close, so check first. On GitHub, the web settings can rename the default branch and redirect things for you.

Example

bash
git branch -m old-name new-name          # local rename
git push origin -u new-name               # publish under new name
git push origin --delete old-name         # remove old name
# on a teammate's machine
git fetch --prune

What to say in the interview

"git branch -m renames locally. For a pushed branch I push the new name with -u, delete the old remote branch, and ask teammates to fetch with --prune and update their tracking. Renaming the default branch is safer through GitHub settings."

#git#branch#rename

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.