In this series of posts I’ll document useful git commands ready to copy&paste which nobody knows by heart but you need once in a while. Today:
git remote prune <name>
From the docs:
Deletes all stale remote-tracking branches under <name>. These stale branches have already been removed from the remote repository referenced by <name>, but are still locally available in “remotes/<name>”.
With --dry-run option, report what branches will be pruned, but do not actually prune them.
Very useful when working with Github and you just merged a PR then usually you also delete the branch on the remote immediately after. This does not however delete the branch from your local repository and over time it can get messy. With this simple command you delete all local branches which were deleted on the server. If your remote is called origin then just type enter it like so::
git remote prune origin