Skip to content

Instantly share code, notes, and snippets.

@Xunnamius
Forked from joejordanbrown/gh-cleanup-releases-tags.sh
Last active November 24, 2024 15:32
Show Gist options
  • Save Xunnamius/7f6cd12e09bd46fb59af91a63ddd4dd7 to your computer and use it in GitHub Desktop.
Save Xunnamius/7f6cd12e09bd46fb59af91a63ddd4dd7 to your computer and use it in GitHub Desktop.
GitHub cli - delete all releases and tags in a repo
#! /bin/sh
# Note that gh! is an alias for gh
for release in $(gh! release list 2>/dev/null | awk '{print $1}'); do
if gh! release delete $release -y | cat; then
echo '✓ Deleted release' $release
else
echo '⤫ FAILED to delete release' $release
fi
done
for tag in $(gh! api repos/:owner/:repo/tags --paginate | jq -r '.[].name'); do
result=$(gh! api repos/:owner/:repo/git/refs/tags/${tag} -X DELETE)
exit_code=$?
if [[ "$exit_code" == '0' ]]; then
echo '✓ Deleted tag' $tag
else
echo $result
echo '⤫ FAILED to delete tag' $tag
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment