gitgit-tag

In git how can I delete all tags(local and remote) except the latest one


I want to delete all the tags (local and remote) in my git repo except the latest one. I have read the posts about deleting all tags but could not find the info about deleting them selectively i.e. delete all tags except the latest one


Solution

  • Somehow I found the answer on Stack Overflow itself. Customized it a bit with my needs.

    Delete all remote tags but keep latest

    git describe --abbrev=0 --tags `git rev-list --tags --skip=1` | xargs -n 1 git push --delete origin
    

    Delete all local tags but keep latest

    git describe --abbrev=0 --tags `git rev-list --tags --skip=1` | xargs -n 1 git tag -d