Created
May 17, 2024 07:33
-
-
Save jrudolph/0df77340d9a35c7051ae04a7a15bd20e to your computer and use it in GitHub Desktop.
Delete local branches that have already been squash merged into origin/main
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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