SHELF / SNIPPET
git-clean-branches.
git-clean-branches() {
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
}
alias clb="git-clean-branches" After a merged PR, the remote branch dies but the local one lingers. This prunes remote-tracking refs (fetch -p), finds local branches whose upstream is gone, and deletes them. Typed as three letters: clb.
The safety is in the lowercase -d — git refuses to delete anything unmerged. The worst case is a "branch not fully merged" warning, which is exactly when you want to be interrupted.