Interview Prep/Git & GitHub/Repository Health, Size and Performance

`git branch -r` lists hundreds of remote branches that were deleted on GitHub months ago.

BeginnerTroubleshootingRepository Health, Size and Performance
Answer

Likely causes → Fetch does not remove remote-tracking refs for deleted branches unless pruning is on.

Diagnose → git remote prune origin --dry-run

Fix →

git fetch --prune
git config --global fetch.prune true
# local branches whose upstream is gone:
git branch -vv | awk '/: gone]/{print $1}' | xargs -r git branch -d

Prevent → Enable "Automatically delete head branches" in the GitHub repo settings and keep fetch.prune=true.

All Git & GitHub questions Roadmap: Git & GitHub

More on Repository Health, Size and Performance