Search code examples
gitgithubgithub-cligithub-release

How to delete all releases and tags in a github repository


I tried the github cli:

gh release list | sed 's/|/ /' | awk '{print $1, $8}' | while read -r line; do gh release delete -y "$line"; done

as described here: https://dev.to/dakdevs/delete-all-releases-from-github-repo-13ad

But it only works for releases where the name equals the tag. As soon as a name has spaces in it, awk fails to separate the columns properly.

maybe the gh cli output changed since the article was written or awk on macos has different defaults?


Solution

  • Adding -F '\t' helped awk to separate the columns correctly. This command deletes all gh releases:

    gh release list \
      | awk -F '\t' '{print $3}' \ 
      | while read -r line; do
      gh release delete -y "$line"
    done
    

    You can also delete the tags with the following flag:

    --cleanup-tag   Delete the specified tag in addition to its release