We all have something similar, it seems! I stole mine from https://stackoverflow.com/questions/7726949/remove-tracking-....
I also set mine up to run on `git checkout master` so that I don't really have to think about it too hard -- it just runs automagically. `gcm` has now become muscle memory for me.
alias gcm=$'git checkout master || git checkout main && git pull && git remote prune origin && git branch -vv | grep \': gone]\'| grep -v "\*" | awk \'{ print $1; }\' | xargs -r git branch -D'
Same using a git alias rather than shell, and without the network bits, it just cleans up branches which have an upstream that has been deleted: