Skip to content

Instantly share code, notes, and snippets.

@jjgonecrypto
Created March 11, 2020 16:20
Show Gist options
  • Save jjgonecrypto/a05d1091b0f73f5d25b05dbefa6898e5 to your computer and use it in GitHub Desktop.
Save jjgonecrypto/a05d1091b0f73f5d25b05dbefa6898e5 to your computer and use it in GitHub Desktop.
git-delete-squashed
#!/bin/sh
# adapted from https://github.com/not-an-aardvark/git-delete-squashed
function git-delete-squashed() {
BASE_BRANCH=${1:-master}
git checkout -q $BASE_BRANCH &&
git for-each-ref refs/heads/ "--format=%(refname:short)" |
while read branch;
do mergeBase=$(git merge-base $BASE_BRANCH $branch) && [[ $(git cherry $BASE_BRANCH $(git commit-tree $(git rev-parse $branch\^{tree}) -p $mergeBase -m _)) == "-"* ]] &&
git branch -D $branch;
done
}
# e.g. usage with a named branch:
# git-delete-squashed develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment