Created
June 15, 2021 14:16
-
-
Save reistiago/b59d69b32e643a0eaa8c769fb4c0bc3a to your computer and use it in GitHub Desktop.
Delete remote branches older than 2 months
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
#!/bin/sh | |
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'master$\|develop$'); do | |
if ! ( [[ -f "$branch" ]] || [[ -d "$branch" ]] ) && [[ "$(git log $branch --since "2 month ago" | wc -l)" -eq 0 ]]; then | |
name=$(echo "$branch" | sed 's/remotes\/origin\///') | |
git push origin --delete "${name}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment