Skip to content

Instantly share code, notes, and snippets.

@reistiago
Created June 15, 2021 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reistiago/b59d69b32e643a0eaa8c769fb4c0bc3a to your computer and use it in GitHub Desktop.
Save reistiago/b59d69b32e643a0eaa8c769fb4c0bc3a to your computer and use it in GitHub Desktop.
Delete remote branches older than 2 months
#!/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