Your repo has 300 stale branches locally and remotely. How do you clean up safely?
BeginnerScenarioBranching and Merging Workflows
Answer
Situation read → Merged branches are safe to delete, others need a check.
What I'd do →
git fetch --pruneto drop stale remote-tracking refs.- List merged local branches:
git branch --merged main, and delete withgit branch -d. - Delete a remote branch:
git push origin --delete old-branch. - Turn on auto-delete of head branches in GitHub and set
fetch.prune true.
git branch --merged main | grep -vE '^\*|main|develop' | xargs -r git branch -d
Why → -d refuses unmerged branches, giving a safety net.
Interview tip → Squash-merged branches will not show in --merged; cross-check with the closed PR list.
More on Branching and Merging Workflows
You run `git pull` and Git stops with a merge conflict in `app.py`. What do you do?BeginnerYour feature branch is three weeks old and `main` has moved a lot. Merge `main` in, or rebase onto it?IntermediateThe team argues about fast-forward merges versus merge commits on `main`. How do you settle it?BeginnerA teammate branched from the wrong base, and their PR shows 40 unrelated commits. How do you fix it?IntermediateBefore merging, you want to see exactly what the feature branch adds compared to `main`. Which commands?BeginnerHalfway through a merge you realise you pulled the wrong branch. How do you back out?Beginner