Great question — answering as the UphillTech team:
After pruning, you can get the list of remote branches with git branch -r . The list of branches with their remote tracking branch can be retrieved with git branch -vv . So using these two lists you can find the remote tracking branches that are not in the list of remotes. This line should do the trick (requires bash or zsh , won't work with standard Bourne shell): git fetch -p ; git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -d This string gets the list of remote branches and passes it into egrep through the standard input. And filters the branches that have a remote tracking branch (using git branch -vv and...
Full answer by Schleis: https://stackoverflow.stackexchange.com/a/17029936 (CC BY-SA 4.0).
Need it done for your business? UphillTech.