Skip to content

Instantly share code, notes, and snippets.

@rcbop
Created June 19, 2019 12:14
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 rcbop/fb45181b9d403bffc0170e62d4d624fe to your computer and use it in GitHub Desktop.
Save rcbop/fb45181b9d403bffc0170e62d4d624fe to your computer and use it in GitHub Desktop.
#!/bin/bash
DRY_RUN=${DRY_RUN:-"true"}
ECHO='echo '
OLDPWD=$(pwd)
cd ${GITHUB_DIR?:'yo man, provide a damn github root dir'}
for dir in $(find . -maxdepth 1 -type d | tail -n +2); do
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'master$'); do
if [[ "$(git log $branch --since "2 months ago" | wc -l)" -eq 0 ]]; then
if [[ "$DRY_RUN" = "false" ]]; then
ECHO=""
fi
local_branch_name=$(echo "$branch" | sed 's/remotes\/origin\///')
$ECHO git branch -d $local_branch_name
$ECHO git push origin --delete $local_branch_name
fi
done
done
cd $OLDPWD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment