Skip to content

Instantly share code, notes, and snippets.

@komuw
Last active September 1, 2016 17:06
Show Gist options
  • Select an option

  • Save komuw/3defd321f9b3ab751906fd201bb1eb2b to your computer and use it in GitHub Desktop.

Select an option

Save komuw/3defd321f9b3ab751906fd201bb1eb2b to your computer and use it in GitHub Desktop.
delete branches that are older than x days
# delete branches that are older than x days
# this will delete branches that havent received any commits that are newer than Aug 10, 2016
# see this answer for a bit more detail: http://stackoverflow.com/questions/10325599/delete-all-branches-that-are-more-than-x-days-weeks-old/39277210#39277210
for k in $(git branch -r | sed /\*/d); do
if [ -z "$(git log -1 --since='Aug 10, 2016' -s $k)" ]; then
branchnew=$(echo $k | sed -e "s/origin\///")
echo deleting branch: $branchnew
git push origin --delete $branchnew
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment