367

I want to delete all the tags from a Git repository. How can I do that?

Using git tag -d tagname delete the tag tagname locally, and using git push --tags I update the tags on the git provider.

I tried:

git tag -d *

But I see that * means the files from the current directory.

$ git tag -d *
error: tag 'file1' not found.
error: tag 'file2' not found.
...

Consider I have a lot of tags, and I want to delete them, all.

20 Answers 20

616
git tag | xargs git tag -d

Simply follow the Unix philosophy where you pipe everything.

On Windows use git bash with the same command.

11
  • 201
    Thanks. This command deletes the local tags. I used git tag -l | xargs -n 1 git push --delete origin to delete them from the remote. Commented Oct 23, 2013 at 13:16
  • 8
    @CoDEmanX On Windows you should use git bash with the same command.
    – inf3rno
    Commented Sep 12, 2015 at 22:28
  • 2
    Doesn't delete remote tags, also very slow for thousands of tags. Commented Jul 20, 2016 at 22:02
  • 2
    'xargs' is not recognized as an internal or external command on windows 10
    – Gulzar
    Commented Aug 29, 2019 at 11:49
  • 3
    Don't forget to run git fetch --all --tags --prune before trying to delete the tags.
    – Akito
    Commented May 23, 2020 at 15:13
341

To delete remote tags (before deleting local tags) simply do:

git tag -l | xargs -n 1 git push --delete origin

and then delete the local copies:

git tag | xargs git tag -d
8
  • 1
    Remote delete is way too slow for dozens of tags.
    – ffxsam
    Commented Jan 2, 2017 at 20:32
  • 13
    This answer is way faster if you have a lot of remote tags: stackoverflow.com/a/34395864/747044
    – adriaan
    Commented Feb 15, 2017 at 17:01
  • 1
    The order of commands in this answer assumes that there are no local-only tags.
    – Asclepius
    Commented Jan 18, 2019 at 0:49
  • This is too slow, below solution is better.
    – Root Fool
    Commented Feb 27, 2020 at 19:58
  • 1
    If you need to enter passphrase for commits, this requires passphrase for each tag. The other solution is better.
    – kap
    Commented Apr 3, 2020 at 21:06
104

It may be more efficient to push delete all the tags in one command. Especially if you have several hundred.

In a suitable non-windows shell, delete all remote tags:

git tag | xargs -L 1 | xargs git push origin --delete

Then delete all local tags:

git tag | xargs -L 1 | xargs git tag --delete

This should be OK as long as you don't have a ' in your tag names. For that, the following commands should be OK.

git tag | xargs -I{} echo '"{}"' | tr \\n \\0 | xargs --null git push origin --delete
git tag | xargs -I{} echo '"{}"' | tr \\n \\0 | xargs --null git tag --delete

Other ways of taking a list of lines, wrapping them in quotes, making them a single line and then passing that line to a command probably exist. Considering this is the ultimate cat skinning environment and all.

6
  • 4
    I had several thousand tags, deleting them one by one from a remote cloud repo was taking days, which this solved. Commented Jul 20, 2016 at 22:03
  • What does the xargs -L 1 do?
    – ymett
    Commented Jul 23, 2019 at 11:42
  • -L max-lines --max-lines[=max-lines] -l[max-lines] Use at most max-lines non-blank input lines per command line. For ‘-l’, max-lines defaults to 1 if omitted. For ‘-L’, the argument is mandatory. Trailing blanks cause an input line to be logically continued on the next input line, for the purpose of counting the lines. Implies ‘-x’. The ‘-l’ form of this option is deprecated in favour of the POSIX-compliant ‘-L’ option. gnu.org/software/findutils/manual/html_node/find_html/… Commented Jul 23, 2019 at 12:13
  • 1
    @RichardAQuadling Ok, but what effect does that have in the answer? git tag returns the tags, one per line, and then xargs -L 1 outputs them one per line, so what's it for?
    – ymett
    Commented Oct 2, 2019 at 10:27
  • 1
    Hmmm. Seemingly nothing in this context! Other than make things a touch slower! Commented Oct 4, 2019 at 10:50
52

For Windows users using PowerShell:

git tag | foreach-object -process { git tag -d $_ }

This deletes all tags returned by git tag by executing git tag -d for each line returned.

3
  • 5
    git tag | foreach-object -process { git tag -d $_ && git push --delete origin $_ } if you also want to delete tags in remote. It will git push --delete ... each tag one by one, which can take some time if there are many tags. Does anyone know how to do this more efficiently?
    – tolache
    Commented Oct 17, 2022 at 8:16
  • 1
    Switch out && with | if powershell gives you the error: "&& is not a valid statement separator in this version" Commented Mar 24, 2023 at 11:34
  • This is dog slow compared to running in Bash or Cygwin.
    – Hugh W
    Commented Jun 26 at 11:31
36

If you don't have the tags in your local repo, you can delete remote tags without have to take it to your local repo.

git ls-remote --tags --refs origin | cut -f2 | xargs git push origin --delete

Don't forget to replace "origin" to your remote handler name.

1
  • Excellent! This deleted them all in one go. The other command was deleting one every 2 seconds
    – fregante
    Commented Mar 27, 2018 at 11:36
33

Adding to Stefan's answer which was missing how to delete tags from remote. For windows powershell you can run this to delete the remote tags first followed by the local tags.

git tag | foreach-object -process { git push origin --delete $_ }
git tag | foreach-object -process { git tag -d $_ }  
20

To delete all the local tags simply run the following command

git tag | xargs git tag -d

To delete remote tags after deleting the local tags by running the above command, you can run the comand below

git ls-remote --tags --refs origin | cut -f2 | xargs git push origin --delete

NOTE: replace origin with your remote handler

1
  • 1
    This one works best out of all the ones listed. The other ones return and error: fatal: --delete doesn't make sense without any refs Commented Apr 30, 2023 at 15:27
15

For windows users:

This deletes all Local Tags by running git tag and feeding that list to git tag -d:

FOR /f "tokens=*" %a in ('git tag') DO git tag -d %a

(Found on: https://gist.github.com/RandomArray/fdaa427878952d9768b0)

11

You can also use:

git tag -d $(git tag)
2
  • this won't work if you have a lot of tags, like thousands
    – DixonD
    Commented Jun 1, 2018 at 13:23
  • in this case you could use something like: git tag -d $(git tag | head -n 999) and execute it x times
    – ViZeke
    Commented Jun 4, 2018 at 18:46
8

I have to delete the tags with prefix

for example, I have to delete the tags v0.0.1, v0.0.2, v0.0.3, v0.0.4, v0.0.5

git tag -d $(git tag -l "v0.0.*")

Decompose and explain the statement above:

  1. To list all the tags with prefix

    git tag -l "v0.0.*"

  2. To delete tags

    git tag -d $tag_names

That's how that statement works

0
3

Since all these options only work in linux, here's the windows equivalent for anybody having to deal with that:

FOR /F usebackq %t IN (`git tag`) DO @git tag --delete %t
3

Powershell v7 supports parallel foreach if you have lots of upstream (origin) tags that you need to delete:

git tag | foreach-object -Parallel { 
git push origin --delete $_ 
git tag -d $_ 
}
2

Recent version parallelized and filtered

git tag -l "v1.0.*" | xargs -L 1 | xargs git push origin --delete
git fetch origin --prune --prune-tags

First line, remove all matching tags from remote in parallel.
Second line, update the current repo by pruning all deleted tags, from git version v2.26.2.

To test the first line you can add --dry-run, I also encourage you to explore the tag list command, it has nice wildcards and exclusion/inclusion.

2

For windows, doing this for removing remote tags:

git fetch --tags
git push origin --delete $(git tag -l)
1

Show all tags containing "v"

git tag -l | grep v | xargs -n 1 sh -c 'echo "Processing tag $0\n" && git show -s $0'
1

A one liner that deletes both local and remote tags with a wild card pattern.

TAGPATTERN="0.1.*" ; git push origin --delete $(git tag -l $TAGPATTERN) ; git tag -d $(git tag -l $TAGPATTERN)

Remote tags are deleted first as the list is generated from local.

1

I didn't find a solution anywhere that didn't requre a git push call per tag, so I came up with this variant, which - in my case - reduced the runtime from several hours to several seconds:

git push --delete origin $( git ls-remote --tags origin | awk '{print $2}' | grep -Ev "\^" | tr '\n' ' ')

Explanation

  • git push --delete origin $(...): Deletes a tag (or multiple) on origin
  • $( git ls-remote --tags origin | awk '{print $2}' | grep -Ev "\^" | tr '\n' ' '): Creates a space delimited string of all tags
    • git ls-remote --tags origin: Prints all tags on the remote origin
    • ... | awk '{print $2}' | ...: Only prints the second column of the previous command output
    • ... | grep -Ev "\^" | ...: Filters out unwanted refs/tags/mytag^{} variants (not sure where they come from)
    • ... | tr '\n' ' ': Converts the list into a space delimited string

It takes advantage of the fact that you can provide multiple tag names in a space delimited string, so it only invokes git delete once.

0
1

You can use those command lines to delete both local and remote tags.

#Delete local tags.
git tag -d $(git tag -l)
#Fetch remote tags.
git fetch
#Delete remote tags.
git push origin --delete $(git tag -l) # Pushing once should be faster than multiple times
#Delete local tags.
git tag -d $(git tag -l)
0

Locally, git tags are just files on disk stored in .git/refs/tags subfolder.

You could just cd .git/refs/tags and remove all files stored there, with your favourite method of deleting files (rm *, delete from files explorer UI etc.)

0

In PowerShell you can just run this:

git tag | % {git tag -d $_}
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Aug 31, 2023 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.