Interview Q&A / Git & GitHub

BeginnerQuick answer1 min readUpdated 3 Oct 2026

How do you delete a branch locally and on the remote?

SHORT ANSWER

Delete it locally with git branch -d name (or -D to force), and delete it on the remote with git push origin --delete name. They are separate; removing one does not remove the other.

Explain it simply

A branch can exist in two places: your laptop and the GitHub server. Deleting it from your laptop does not touch the server copy, like removing a contact from your phone but not from your SIM backup.

-d is the safe delete; Git refuses if the branch has commits not merged elsewhere. -D forces it. For the server use git push origin --delete feature/x. Other people's laptops may still show origin/feature/x; they clean it with git fetch --prune. You cannot delete the branch you are currently on, so switch away first.

Example

bash
git switch main
git branch -d feature/login            # safe delete
git branch -D feature/experiment       # force delete
git push origin --delete feature/login # delete on GitHub
git fetch --prune                      # clean stale remote-tracking refs

What to say in the interview

"git branch -d deletes a merged local branch, -D forces it, and git push origin --delete removes it from the remote. They are independent, and teammates can tidy their stale remote-tracking branches with git fetch --prune."

#git#branch#remote

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.