Skip to content

Instantly share code, notes, and snippets.

@chmouel
Last active September 14, 2022 15:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chmouel/6171903 to your computer and use it in GitHub Desktop.
Save chmouel/6171903 to your computer and use it in GitHub Desktop.
Delete merged gerrit git branch using Change-ID
#!/bin/zsh
declare -a unmerged
git rev-parse --show-toplevel 2>/dev/null >/dev/null || { echo "Not a git dir"; exit 1 ;}
git fetch origin;
git branch --merged|grep -v 'master'|xargs git branch -d
for branch in $( git branch --no-merged );do
LOG=$(git log --format=%h --grep $(git log -n1 ${branch}|grep Change-Id|sed 's/.* //'))
if [[ -n ${LOG} ]];then
echo "${branch} was merged in commit ${LOG}"
git branch -D ${branch}
else
unmerged=("$unmerged[@]" ${branch})
fi
done
echo "unmerged branches are: "
for i in ${unmerged[@]};do
echo $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment