git remote prune: Usage, Options & Common CI Errors
git remote prune removes the local stand-ins for branches that were deleted on the remote.
After PRs merge and branches are deleted upstream, your origin/* refs go stale. Pruning keeps branch listings and ref iterations honest in long-lived caches and CI workspaces.
What it does
git remote prune deletes remote-tracking references under refs/remotes/<remote>/ that no longer have a corresponding branch on the remote. It does not touch local branches or remote data.
Common usage
git remote prune origin
git remote prune --dry-run origin
# equivalent during a fetch:
git fetch --prune originOptions
| Flag | What it does |
|---|---|
| <remote> | The remote whose stale refs to prune |
| -n / --dry-run | Show what would be pruned |
| (via fetch) --prune | Prune as part of a fetch |
Common errors in CI
Pruning only removes remote-tracking refs, not your local branches - a local branch whose upstream vanished still lingers and may show "gone" in git branch -vv. Use git fetch --prune to refresh and prune in one step; --dry-run first if a script deletes based on the output.