Remove all merged (into master) remote branches First run with --dry-run and check if everything is OK
git branch -r --merged origin/master |
grep origin |
grep -v '>' |
grep -v master |
xargs -L1 |
cut -d"/" -f2- |
xargs git push origin --dry-run --delete
Remove tracking branches if the remote branch is deleted
git remote prune origin
Remove all local branches if remote upstreams are removed
git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -d