Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
count=`git tag -l | wc -l`
keep=20
num=0
for t in `git tag -l --sort=taggerdate`
do
if [ "$num" -ge `expr $count - $keep` ]
then
break
fi
git push origin :$t
git tag -d $t
num=`expr $num + 1`
echo "[$num] Removed $t"
done
@drmax24

This comment has been minimized.

Copy link

@drmax24 drmax24 commented Jul 31, 2017

It does not delete old tags. It sorts them alphabetically and deletes based on alphabetic position

@TheJosh

This comment has been minimized.

Copy link

@TheJosh TheJosh commented Aug 10, 2017

Thanks! Works perfectly for my deployment tags (which are named YYYY-MM-DD)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment