Last active
February 16, 2021 15:21
-
-
Save michaelsauter/297c0a67ba277b9c508f933ef9f70cdf to your computer and use it in GitHub Desktop.
Find and remove old Git branches
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
# Update local repo | |
git fetch origin --prune | |
# Merged branches at least 2 months old | |
for branch in `git branch -r --merged | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | grep "months" | awk '{print $(NF)}' | sed -e "s/^origin\///" | xargs git push origin --delete --dry-run | |
# All branches at least a year old | |
for branch in `git branch -r | grep -v HEAD`; do echo -e `git show --format="%ci %cr %an" $branch | head -n 1` \\t$branch; done | grep "1 year" | awk '{print $(NF)}' | sed -e "s/^origin\///" | xargs git push origin --delete --dry-run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment