bin/git-delete-merged-branches
#!/usr/bin/env bash
#
# Quick script to purge all the branches that have been merged to a target
# branch (defaults to the repository's default branch)
if [[ $# != 1 ]]; then
mergedInto="$(git origin-head)"
else
mergedInto="$1"
fi
currentBranch=$(git symbolic-ref --short HEAD)
if [[ "${currentBranch}" != "${mergedInto}" ]]; then
echo "You have to be on the same git branch you're using as the merge target"
exit 1
fi
git branch --merged "${mergedInto}" | grep -v "^[*+]" | xargs -n 1 git branch -d