jasonmccreary / git-trim

MIT License
367 stars 10 forks source link

clean up squashed-and-merged branches #20

Open jjb opened 8 months ago

jjb commented 8 months ago

Hi - thanks for a neat project!

I believe none of these will clean up squashed-and-merged branches (other than getting included in stale, untracked, or reset)

Here's what I use for that

[alias]
  delete-squashed = "!f() { local targetBranch=${1:-master} && git checkout -q $targetBranch && git branch --merged | grep -v \"\\*\" | xargs -n 1 git branch -d && git for-each-ref refs/heads/ \"--format=%(refname:short)\" | while read branch; do mergeBase=$(git merge-base $targetBranch $branch) && [[ $(git cherry $targetBranch $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == \"-\"* ]] && git branch -D $branch; done; }; f"

maybe it could go into the project

jasonmccreary commented 8 months ago

Thanks.

Yes, as someone who does "Squash Merges" for nasty PRs, I would want this. I'm open to seeing it added to the project.