Skip to content

Instantly share code, notes, and snippets.

@arzzen
Last active January 30, 2023 03:27
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save arzzen/9a5c8a371c4a6258f4e1380cd9414eb1 to your computer and use it in GitHub Desktop.
Save arzzen/9a5c8a371c4a6258f4e1380cd9414eb1 to your computer and use it in GitHub Desktop.
#!/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
Copy link

drmax24 commented Jul 31, 2017

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

@TheJosh
Copy link

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