How do you rename a Git branch, including one already pushed?
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
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 --pruneWhat 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."