#!/bin/bash # Find local branches that have been squash-merged into a target branch. # Usage: git-find-merged [target-branch] # Default target branch: main target="${1:-main}" git for-each-ref refs/heads/ --format='%(refname:short)' | while read branch; do [[ "$branch" == "$target" ]] && continue merge_base=$(git merge-base "$target" "$branch" 2>/dev/null) || continue tree=$(git rev-parse "$branch^{tree}" 2>/dev/null) || continue squash_commit=$(git commit-tree "$tree" -p "$merge_base" -m "test" 2>/dev/null) || continue cherry_result=$(git cherry "$target" "$squash_commit" 2>/dev/null) if [[ "$cherry_result" == "-"* ]]; then echo "$branch" fi done