Last active
October 14, 2021 12:01
-
-
Save bvanskiver/72d2ac4f6dd02afd1de9cd3b59aa9c48 to your computer and use it in GitHub Desktop.
This file contains 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
# 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