If deleted branches still appear in Git on your Mac, prune the remote-tracking references from your local repository. Open Terminal, change to the repository folder, check which remote you want to refresh, then run git fetch --prune origin. This updates fetched references and removes stale ones associated with origin; it does not delete branches from the remote server or remove your local branches. Git’s git fetch documentation
What gets refreshed when you prune?
A remote-tracking branch is your local record of a branch on a remote repository. For example, origin/feature-x represents the last fetched state of the remote branch. It is separate from a local branch named feature-x. If the remote branch is deleted, your local reference may remain until Git prunes it. Git’s default fetch mapping commonly stores remote branches under refs/remotes/origin/, though a repository can use a different mapping. Git documents how configured fetch refspecs map remote branches.
Pruning compares the remote’s current references with the local references covered by that remote’s fetch configuration, then removes references that no longer exist remotely. It cleans up your local view; it is not a command to delete remote branches. This can make commands such as git branch --all easier to read when a repository has accumulated old branch references. Git’s pruning guidance
Refresh references from Terminal
Apple documents zsh as the default shell in Terminal on Mac, although a Mac or managed environment can be configured differently. The Git commands below work in the usual macOS Terminal setup. Apple’s Terminal User Guide
- Open Terminal and go to the repository’s folder. If you know its path, quote it when it contains spaces, for example:
cd "/Users/sam/Projects/Client App"
Replace the example path with your repository’s actual path. If you are unsure where you are, pwd prints the current directory. Run the Git commands from inside the repository.
- Confirm the repository and remote name:
git status --short --branch
git remote -v
git remote -v lists the configured remote names and URLs. origin is common, but use the name shown for the server whose references you want to refresh. If the repository has several remotes, prune only the intended one.
- Preview stale references before removing them:
git remote prune --dry-run origin
Git reports which references it would prune without deleting them. The dry-run option belongs to git remote prune; it does not fetch new branch tips. Git’s git remote documentation
- If the preview matches what you expect, refresh and prune in one step:
git fetch --prune origin
This fetches according to the remote’s configured refspec and removes stale references covered by that mapping. Git’s fetch output marks a pruned reference with -. To prune without fetching updates, use git remote prune origin instead. Git documents both one-off methods.
- Check the result:
git branch --remotes
git branch --all
The remote-only listing shows remote-tracking branches; the all-branches listing includes both remote-tracking and local branches. A branch absent from the remote listing may still exist as a local branch, and pruning does not remove it.
If the stale reference remains
First check that you used the correct remote name. Then consider the repository’s fetch configuration: remotes can be set to track only selected branches, and custom refspecs change which references fetch and prune act on. Inspect the mapping with git config --get-all remote.origin.fetch, replacing origin if needed. If the remote is configured to track only a subset, branches outside that subset may not behave as expected under a default fetch. Git explains fetch refspecs and their effect on pruning.
If the command reports a network or authentication error, Git could not complete the remote fetch; resolve the connection or access issue and retry. Avoid adding --prune-tags unless you specifically want pruning applied to tags too: Git warns that explicit tag refspecs can cause local tags missing from that remote to be removed. Git’s pruning documentation explains this tag caveat.
Use git fetch --prune origin when you want current remote-tracking information and cleanup together. Use git remote prune --dry-run origin first when you want to review the candidates, or git remote prune origin when you want cleanup without fetching branch updates.
Sources
Change the default shell in Terminal on Mac — Apple Support