Skip to content

Instantly share code, notes, and snippets.

@cxreg
Created February 26, 2013 22:08
Show Gist options
  • Save cxreg/5042722 to your computer and use it in GitHub Desktop.
Save cxreg/5042722 to your computer and use it in GitHub Desktop.
git-cleanup
#!/bin/bash
if [[ $1 != "-f" ]]; then
echo "### Dry-run mode, specify -f to actually perform deletes.";
fi;
for branch in $(git branch -r --merged origin/master | grep '\<origin/' | grep -v '\<origin/master\>');
do
if [[ -z $(git rev-list $branch --since '1 month') ]]; then
name=$(echo $branch | sed 's/^origin\///');
if [[ $1 = "-f" ]]; then
git push --delete origin "$name";
else
echo git push --delete origin "$name";
fi;
fi;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment