A branch disappears from the hosting service, yet its name remains in your local branch picker. Removing that stale remote-tracking reference can clarify the view. Before pruning, inspect how the remote maps references into your repository: a custom mapping can make the cleanup affect more than the names you expected.
The commands assume a remote named origin. Inspect its mappings first: the default branch mapping, an explicit tag mapping, and a mirror have different deletion scopes. The worked example keeps a local development branch and a local tag while removing one stale remote-tracking reference.
Identify the reference you are looking at
A local development branch and a remote-tracking reference have different purposes. In a synthetic repository, topic/report may be your editable branch while origin/topic/report records an observation of the remote branch. Their similar names do not make them interchangeable.
Start by deciding what evidence you need. If the question is whether the server still advertises a branch, an old local observation is insufficient. If the question is whether your own work remains reachable, the server's branch list is also insufficient. Keep both questions in the maintenance record so that clearing the interface does not become an accidental decision about retaining work.
The Git fetch manual explains that pruning follows reference mappings, called refspecs. With an ordinary heads-to-remote-tracking mapping, stale remote-tracking branches are the relevant targets. Explicit tag mappings introduce a different deletion scope. Treat that distinction as a prerequisite for cleanup, especially in repositories with multiple remotes or mirroring configuration.
Inspect the configured destination namespace
In a terminal at the intended repository root, these read-only commands work in Bash and PowerShell with Git installed:
git status --short --branch
git config --get-all remote.origin.fetch
git for-each-ref --format='%(refname)' refs/remotes/origin/
The status identifies your current branch context. The configuration shows the mapping you need to interpret. The reference listing identifies the local namespace being inspected. These commands avoid printing remote URLs, which can contain information unrelated to the maintenance decision.
An ordinary mapping looks like this:
+refs/heads/*:refs/remotes/origin/*
The left side selects branches advertised by the server. The right side selects the local references that fetch updates. The leading + permits those destination references to move even when their old value is not an ancestor of the new value. It does not merge those commits into your checked-out branch.
Now compare a mapping that also includes refs/tags/*:refs/tags/*. Its destination is the local tag namespace, shared with locally created tags and potentially other remotes. Pruning that mapping can remove a local tag absent from this particular remote. The name origin does not limit pruning to refs/remotes/origin/; the destination determines the scope.
If no mapping is printed, record that result instead of silently substituting a default. The repository may use explicit command-line refspecs or a nonstandard workflow. Resolve the configuration question before selecting a cleanup command.
Preview removal before changing references
Once the mapping is understood, inspect the proposed stale references:
git remote prune --dry-run origin
The remote command reference documents this preview. It contacts the remote, so successful authentication and network access matter. A failed connection provides no evidence that the advertised branches are gone. Keep the last known local state until the remote can be inspected successfully.
Compare every proposed deletion with the namespace you approved. If the preview includes a tag or another unexpected reference, investigate the mapping and pruning settings. Avoid adding tag pruning as a convenience when the actual task concerns stale development branch observations.
For a repository whose reviewed configuration has the intended scope, the corresponding fetch-and-prune operation is:
git fetch --prune origin
Read its result before proceeding. Do not interpret a partially failed remote operation as a completed maintenance task. If retaining a particular observed commit matters, preserve it under a deliberately named local reference before cleanup, following your team's retention practice.
Give local branch deletion its own review
Consider a disposable fixture with three local references before cleanup:
refs/remotes/origin/topic/report
refs/heads/topic/report
refs/tags/local-review
The server has deleted refs/heads/topic/report. With only the ordinary branch mapping above and tag pruning disabled, fetch-and-prune should remove the first local reference while retaining the second and third. The working tree should remain on the same branch with the same files. These are separate assertions, not three spellings of the same branch.
Check the retained local branch and tag explicitly:
git show-ref --verify refs/heads/topic/report
git show-ref --verify refs/tags/local-review
git for-each-ref --format='%(refname)' refs/remotes/origin/
The first two commands should print their reference and object ID in that fixture. The last should omit the deleted remote-tracking name. If the local branch is absent, investigate a separate action or a different mapping; ordinary remote-tracking cleanup does not explain its deletion. If the fetch failed to contact the server, stop before using the resulting list as a fresh inventory.
After pruning, a local branch may still exist. Decide whether to keep it from its commits, ownership, and intended destination. A remote branch can disappear because work was merged, abandoned, renamed, or moved. Those cases have different implications for local work.
For the synthetic report branch, ask whether its final commit is represented in the supported integration history and whether any additional local commits remain. A hosting service's merge badge may be useful context, but verify the repository state relevant to your workflow. Squash merges and rebases can change commit identity while retaining some intended changes.
Do not turn this review into bulk forced deletion. Separate stale remote observations from locally owned work, and leave ambiguous branches for their owners. The reflog recovery guide describes recovery evidence, but recovery should not be the retention strategy for routine cleanup.
Verify the result and keep the scope explicit
Repeat the reference listing after the operation and compare it with the preview. Confirm that expected active remote-tracking references remain. Then inspect the local branches independently so that a cleaner remote list does not conceal an unfinished branch-retention decision.
Before automating the fixture's procedure, add two failure cases: an unavailable remote and a destination outside the approved namespace. Neither should lead an automation wrapper to report successful branch maintenance or proceed to local branch deletion.
Enable automatic pruning only after that behavior is understood by the people using the repository. Record whether tag pruning is permitted and who owns custom refspecs. The useful maintenance outcome is a reference view that accurately describes its scope, with local work retained or removed through a separate, reviewable decision.
Was this guide useful?
Your rating helps us prioritize clearer, more practical technical content.
Review diffs, run checks, and prepare the release in Arezgit.
Keep Git review, security scanning, API checks, database inspection, and release preparation together in one local desktop application.
Explore Arezgit