Skip to content

Instantly share code, notes, and snippets.

@blakek
Last active October 6, 2022 12:45
Show Gist options
  • Save blakek/5db333bcfcff3c6d7f2f6f3b9dd63b81 to your computer and use it in GitHub Desktop.
Save blakek/5db333bcfcff3c6d7f2f6f3b9dd63b81 to your computer and use it in GitHub Desktop.
Simple command to test if a branch was squashed/rebased and then merged into another. Not tested very much.
#! /usr/bin/env bash
merged=()
unmerged=()
for branch in $(git for-each-ref --format="%(refname:short)" refs/heads); do
if wasBranchMerged "$branch" staging; then
merged+=("$branch")
else
unmerged+=("$branch")
fi
done
echo "Okay to delete:"
echo "${merged[*]}"
echo "Hang on to:"
echo "${unmerged[*]}"
#! /usr/bin/env bash
wasBranchMerged() {
local branch="$1"
local targetBranch="$2"
local searchString="Merge branch '$branch' into '$targetBranch'"
git log --oneline --merges "$targetBranch" | grep -q "$searchString"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment