Skip to content

Instantly share code, notes, and snippets.

@bvanskiver
Last active October 14, 2021 12:01
Show Gist options
  • Save bvanskiver/72d2ac4f6dd02afd1de9cd3b59aa9c48 to your computer and use it in GitHub Desktop.
Save bvanskiver/72d2ac4f6dd02afd1de9cd3b59aa9c48 to your computer and use it in GitHub Desktop.
# Iterate through folders of git repos and show merged branches older than 3 months
for d in */; do
cd "$d" && echo "*********** $d ***********" &&
if [ -d .git ]; then
git fetch --prune --quiet origin &&
for k in $(git branch -r --merged | egrep -v 'HEAD|main|master'); do
if [ -z "$(git log -1 --since='3 months ago' -s $k)" ]; then
echo -e `git show --format="%ci %cr %an" $k | head -n 1` \\t$k;
fi
done | sort -r
else
echo "Not a git repository, skipping.";
fi
cd .. && echo
done
# Iterate through folders of git repos and delete merged branches older than 3 months
for d in */; do
cd "$d" && echo "*********** $d ***********" &&
if [ -d .git ]; then
git fetch --prune --quiet origin &&
for k in $(git branch -r --merged | egrep -v 'HEAD|main|master'); do
if [ -z "$(git log -1 --since='3 months ago' -s $k)" ]; then
git push --delete origin ${k//origin\/}
fi
done
git fetch --prune --quiet origin
else
echo "Not a git repository, skipping.";
fi
cd .. && echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment