Skip to content

Instantly share code, notes, and snippets.

@mattn
Last active February 24, 2026 04:20
Show Gist options
  • Select an option

  • Save mattn/06594c6d59e178333e8024306ae7079f to your computer and use it in GitHub Desktop.

Select an option

Save mattn/06594c6d59e178333e8024306ae7079f to your computer and use it in GitHub Desktop.
[alias]
sweep-branch = "!git for-each-ref refs/heads/ --format=\"%(refname:short)\" | while read branch; do [ \"$branch\" = main ] || [ \"$branch\" = master ] && continue; git rev-parse --abbrev-ref HEAD | grep -qx \"$branch\" && continue; mergeBase=$(git merge-base main \"$branch\" 2>/dev/null) || continue; treeCommit=$(git commit-tree \"$(git rev-parse \"$branch^{tree}\")\" -p \"$mergeBase\" -m _); cherry=$(git cherry main \"$treeCommit\" 2>/dev/null); case \"$cherry\" in \"-\"*) git branch -D \"$branch\" ;; esac; done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment