Skip to content

Instantly share code, notes, and snippets.

@jrudolph
Created May 17, 2024 07:33
Show Gist options
  • Save jrudolph/0df77340d9a35c7051ae04a7a15bd20e to your computer and use it in GitHub Desktop.
Save jrudolph/0df77340d9a35c7051ae04a7a15bd20e to your computer and use it in GitHub Desktop.
Delete local branches that have already been squash merged into origin/main
# adapted from https://github.com/not-an-aardvark/git-delete-squashed
git checkout -q origin/main && git for-each-ref refs/heads/ "--format=%(refname:short)" | \
while read branch; do mergeBase=$(git merge-base origin/main $branch) && \
[[ $(git cherry origin/main $(git commit-tree $(git rev-parse "$branch^{tree}") -p $mergeBase -m _)) == "-"* ]] && \
git branch -D $branch; \
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment