#!/bin/bash git for-each-ref --format='%(refname)' refs/heads/ |while read -r ref; do if git merge-base --is-ancestor "$ref" "refs/remotes/origin/${ref#refs/heads/}"; then echo "${ref#refs/heads/}" fi done | xargs -r git branch -D