Add git_find_merged_branches script.

This commit is contained in:
Tom Alexander
2026-05-06 09:56:18 -04:00
parent 856e4daee6
commit d9c4f824d2
2 changed files with 13 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env bash
#
# Find local branches that have been merged
set -euo pipefail
IFS=$'\n\t'
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
: ${MAIN_BRANCH:="main"}
git checkout -q ${MAIN_BRANCH} && git for-each-ref refs/heads/ "--format=%(refname:short)" | while read branch; do mergeBase=$(git merge-base ${MAIN_BRANCH} $branch) && [[ $(git cherry ${MAIN_BRANCH} $(git commit-tree $(git rev-parse "$branch^{tree}") -p $mergeBase -m _)) == "-"* ]] && echo "$branch"; done