Skip to content

Instantly share code, notes, and snippets.

@paulscott
Created August 10, 2019 01:07
Show Gist options
  • Save paulscott/663acf68433fef75c436f29ed06b17da to your computer and use it in GitHub Desktop.
Save paulscott/663acf68433fef75c436f29ed06b17da to your computer and use it in GitHub Desktop.
Utility to show squash-merged branches that should be pruned
#!/bin/bash
git for-each-ref refs/heads/ "--format=%(refname:short)" |
while read branch; do
mergeBase=$(git merge-base HEAD "${branch}" )
tree=$(git rev-parse "${branch}^{tree}")
tempCommit=$(git commit-tree "${tree}" -p "${mergeBase}" -m "_" )
if [[ $(git cherry HEAD "${tempCommit}") == "-"* ]]; then
echo "git branch -D ${branch}"
fi
done
git prune
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment