Skip to content

Instantly share code, notes, and snippets.

@sbmadhav
Last active September 22, 2020 01:38
Show Gist options
  • Save sbmadhav/0828d878a991ea79efc2539bbf7a0dde to your computer and use it in GitHub Desktop.
Save sbmadhav/0828d878a991ea79efc2539bbf7a0dde to your computer and use it in GitHub Desktop.
Delete git branches that did not receive any commits in the last two months
#!/bin/bash
for k in $(git branch -r | sed /\*/d); do
if [ -z "$(git log -1 --since='2 months' -s $k)" ]; then
branch_name_with_no_origin=$(echo $k | sed -e "s/origin\///")
# echo deleting branch: $branch_name_with_no_origin
git push origin --no-verify --delete $branch_name_with_no_origin
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment