Usually you can remove branches that have been deleted on remote with prune (git fetch -p). Although sometimes there are stale branches and it needs a different approach. Reference to original source: How to prune local tracking branches that do not exist on remote anymore.
Source code viewer
git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs git branch -dProgramming Language: Bash