Interview Q&A / Git & GitHub

BeginnerQuick answer1 min readUpdated 3 Oct 2026

How do you find which branches are already merged into main?

SHORT ANSWER

Run git branch --merged main to list branches whose commits are all in main, and git branch --no-merged main for the rest. Merged ones are usually safe to delete.

Explain it simply

After a few months a repo collects branches like old exam notebooks. Before throwing any away you want to know which ones have been fully copied into the main file.

git branch --merged main lists branches whose tip is reachable from main, so deleting them loses nothing. --no-merged shows those still carrying unique work. Add -r for remote branches. One catch: squash-merged branches count as not merged, because the original commits never entered main.

Example

bash
git branch --merged main
#   feature/login
#   fix/typo
git branch --no-merged main
#   feature/reports
git branch --merged main | grep -v main | xargs git branch -d

What to say in the interview

"git branch --merged main lists branches fully contained in main, which are safe to delete, and --no-merged lists those with unique commits. Branches merged by squash show up as unmerged, so I check those manually before deleting."

Common mistakes

  • Trusting --merged for squash-merged pull requests.

#git#branch#cleanup

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.