tj.git-extras/bin/git-delete-squashed-branches

18 lines
462 B
Bash
Executable file

#!/usr/bin/env bash
targetBranch=$1
if [[ -z $targetBranch ]]; then
targetBranch=$(git rev-parse --abbrev-ref HEAD)
else
git checkout $targetBranch
fi
git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do
mergeBase=$(git merge-base $targetBranch $branch)
if [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch\^{tree}) -p $mergeBase -m _)) == "-"* ]]; then
git branch -D $branch
fi
done