Skip to content

Instantly share code, notes, and snippets.

@originalhat
Forked from antonio/delete_branches_older_than.sh
Last active September 11, 2015 15:46
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 originalhat/5a743d5fe4b2ebd6e89f to your computer and use it in GitHub Desktop.
Save originalhat/5a743d5fe4b2ebd6e89f to your computer and use it in GitHub Desktop.
Script to delete branches older than a certain date
#!/bin/sh
date=$1
for branch in $(git branch -a | sed 's/^\s*//' | sed 's/^remotes\///' | grep -v 'master$'); do
if [[ "$(git log $branch --since $date | wc -l)" -eq 0 ]]; then
if [[ "$branch" =~ "origin/" ]]; then
local_branch_name=$(echo "$branch" | sed 's/^origin\///')
if [[ "$DRY_RUN" -eq 1 ]]; then
echo "git push origin :$local_branch_name"
else
git push origin :$local_branch_name
fi
else
if [[ "$DRY_RUN" -eq 1 ]]; then
echo "git branch -D $branch"
else
git branch -D $branch
fi
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment