What is the difference between git fetch --prune and git remote prune?
Why Interviewers Ask This
Senior Git & GitHub engineers are expected to reason about architecture, performance, and edge cases. This question separates mid-level from senior candidates by testing deep system-level understanding.
Answer
Both commands remove stale remote-tracking references (like origin/deleted-branch) that no longer exist on the remote, but they operate differently: git fetch --prune (or git fetch -p) fetches all updates from the remote AND simultaneously removes any remote-tracking references that no longer exist on the remote. One command does both. Set as default: git config --global fetch.prune true — prune automatically on every fetch. git pull --prune — same but also merges. git remote prune origin only prunes stale remote-tracking refs for the specified remote — it does NOT fetch new changes. Use it when you want to clean up without pulling. Why pruning is needed: when a remote branch is deleted (after merging a PR), your local origin/feature-x reference remains. Over time, you accumulate many stale references. git branch -a shows them all. Check what would be pruned: git remote prune origin --dry-run. After pruning, git branch -vv shows local branches whose tracking is gone: [origin/feature: gone] — these can be safely deleted: git branch -d feature. Automate: git config --global fetch.prune true in your global gitconfig.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last Git & GitHub project, I used this when...' immediately makes your answer more credible and memorable.
Previous
What is git commit signing with GPG or SSH?
Next
How do you handle a monorepo with different services needing independent versioning in Git?