Last active
September 14, 2022 15:56
-
-
Save chmouel/6171903 to your computer and use it in GitHub Desktop.
Delete merged gerrit git branch using Change-ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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