🔀 The Deleted Branch Nobody’s Clone Noticed
When a branch gets deleted on the remote – after a merge, during cleanup, however it happens – every clone that already has a local remote-tracking reference for it just keeps that reference around. A plain git fetch updates the branches that still exist; it doesn’t go out of its way to remove tracking references for ones that don’t, so origin/old-feature can sit in git branch -r for months after the branch itself is long gone.
🔎 The Problem
$ git fetch origin
# Fetches updates for branches that still exist on the
# remote - does nothing about ones that were deleted there.
$ git branch -r
origin/main
origin/feature-payments
origin/old-feature # deleted on the remote weeks ago,
# but still listed here locally.
$ git checkout old-feature
# Still works, still checks out a local tracking branch -
# nothing about this tells you the remote copy is gone.</pre>
✅ Fix: Prune Stale Tracking Refs Explicitly
- Run
git fetch --prune(orgit fetch -p) to remove local remote-tracking references for branches that no longer exist on the remote – this only touches the tracking refs underrefs/remotes/origin/*, it won’t touch any local branch you created yourself. - Set
git config --global fetch.prune trueonce, and every futuregit fetch(andgit pull, which calls fetch internally) prunes automatically – there’s rarely a good reason to keep stale remote-tracking refs around on purpose, so making this the default removes a recurring manual step. git remote prune origin --dry-runshows exactly which tracking references would be removed before you commit to it – useful the first time you turn this on for an older clone that’s accumulated a long list of stale references over time.
⚠️ Why This Is Easy to Miss
- A stale tracking reference doesn’t error or warn about anything – git branch -r and tab-completion both happily keep offering a branch name that hasn’t pointed at anything live on the remote in a long time.
- It’s genuinely confusing in a team setting: one teammate’s clone has already pruned the reference and shows the branch as gone, while another’s hasn’t fetched with –prune recently and still sees it listed – both are looking at the same remote, just through differently stale local caches of it.
Deleting a branch on the remote doesn’t delete anyone’s memory of it – every clone keeps its own tracking reference until something actually tells it to clean up.

