Skip to content

Instantly share code, notes, and snippets.

@drkibitz
Last active June 6, 2023 03:32
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 drkibitz/e3bbf0b8bd4bee8cefc2d643f8e8042f to your computer and use it in GitHub Desktop.
Save drkibitz/e3bbf0b8bd4bee8cefc2d643f8e8042f to your computer and use it in GitHub Desktop.
Delete all remote Git tags in pages
#!/usr/bin/env bash
## Count local
totalCount=$(git tag -l | wc -l)
pageCount=150
index=0
while [ $index -le $totalCount ]; do
## Reverse order with `sort -r`
list=$(git tag -l | sort | head -n $pageCount)
## Check if remote deleted successfully
if git push origin --delete $list; then
## Delete locally only if remote deleted successfully
git tag -d $list
## Next page
x=$(($index + $pageCount))
## Failed to delete remotely
else
## Delete all local and fetch all from remote again
git tag -l | xargs git tag -d
git fetch
## Do over
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment