Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

git-tag

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

like image 444
KKK Avatar asked Oct 20 '25 14:10

KKK


2 Answers

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
like image 169
KKK Avatar answered Oct 23 '25 06:10

KKK


To delete locally all tags:

git tag -d `git tag | grep -E '.'`

Note: Windows users will need to replace grep -E with findstr

The original solution was found here.

like image 21
deadfish Avatar answered Oct 23 '25 07:10

deadfish