Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Delete all git remote tags
#Delete local tags.
git tag -l | xargs git tag -d
#Fetch remote tags.
git fetch
#Delete remote tags.
git tag -l | xargs -n 1 git push --delete origin
#Delete local tasg.
git tag -l | xargs git tag -d
@Graham-72
Copy link

Graham-72 commented Mar 15, 2015

When I tried this from Git Bash on my Windows PC, line 6 was requiring me to log back in to GitHub for each tag. Is there some way to delete all the tags as a batch?

@Graham-72
Copy link

Graham-72 commented Mar 15, 2015

I have found the answer to my question - set up Git Bash credentials as follows:
Enter username and email with
git config --global user.name "YOUR NAME"
git config --global user.email "YOUR EMAIL ADDRESS"

Then use credential helper with
git config --global credential.helper wincred
git config --global credential.helper store

This last line stores password for use by Git Bash each time one is requested.

@robertmhaas
Copy link

robertmhaas commented Jun 9, 2015

The "-n 1" in the example above does not seem to be necessary, and removing it makes this much faster.

@wickdninja
Copy link

wickdninja commented Mar 22, 2017

Confirmed removing -n 1 deletes all tags as a batch which is much faster.

@KSXGitHub
Copy link

KSXGitHub commented Apr 13, 2017

What about this?

#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)

@noxify
Copy link

noxify commented May 1, 2017

Works perfect @KSXGitHub

@keesdewit82
Copy link

keesdewit82 commented Jul 10, 2017

@KSXGitHub works very well!

@wyt
Copy link

wyt commented Jun 6, 2018

nice.

@ehimsi
Copy link

ehimsi commented Jun 13, 2018

thanks

@rruprai
Copy link

rruprai commented Mar 4, 2019

When I run git push origin --delete $(git tag -l) # Pushing once should be faster than multiple times, I get the following error. Any suggestions on how to fix this?

Error:

fatal: --delete doesn't make sense without any refs

@heykarimoff
Copy link

heykarimoff commented Mar 29, 2019

@userraj

When I run git push origin --delete $(git tag -l) # Pushing once should be faster than multiple times, I get the following error. Any suggestions on how to fix this?

Error:

fatal: --delete doesn't make sense without any refs

You don't have local tags to reference.
Run following:

#Fetch remote tags.
git fetch
#Delete remote tags.
git push origin --delete $(git tag -l)
#Delete local tags.
git tag -d $(git tag -l)

@liuliangsir
Copy link

liuliangsir commented Sep 25, 2019

nice, The "git tag -l | xargs git tag -d" in the example above might work better with "grep "

@Paschalis
Copy link

Paschalis commented Apr 4, 2020

if any of the remote tags do not exist, the delete all approach bails out!

@glevand
Copy link

glevand commented Aug 27, 2020

This will get the tags that are on the remote 'origin', then delete those tags:
git ls-remote --tags origin | cut -f 2 | xargs git push --delete origin

@jakeonfire
Copy link

jakeonfire commented Jul 13, 2021

to delete refs as well:

git ls-remote origin | cut -f 2 | grep -iv head | xargs git push --delete origin

@markusressel
Copy link

markusressel commented Aug 5, 2022

I didn't find a solution anywhere that didn't requre a single 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment