Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all git origin and local tags?

How do you remove a git tag that has already been pushed? Delete all git remote (origin) tags and Delete all git local tags.

like image 527
Amir Hosseinzadeh Avatar asked Jun 22 '17 14:06

Amir Hosseinzadeh


People also ask

How do I remove tags on Origin?

To delete the Git tag from the CodeCommit repository, run the git push remote-name --delete tag-name command where remote-name is the nickname the local repo uses for the CodeCommit repository and tag-name is the name of the Git tag you want to delete from the CodeCommit repository.

How do I remove old tags from github?

To delete a local git tag simply run the "git tag" command with the -d option and tag name. To know the tag name you can run the "git tag" command with the -l option to list all tags, identify the tag you want to delete.

How do I delete all files in git?

In order to delete files recursively on Git, you have to use the “git rm” command with the “-r” option for recursive and specify the list of files to be deleted. This is particularly handy when you need to delete an entire directory or a subset of files inside a directory.


3 Answers

  1. Delete All local tags. (Optional Recommended)
    git tag -d $(git tag -l)
    
  2. Fetch remote All tags. (Optional Recommended)
    git fetch
    
  3. Delete All remote tags.
    # Note: pushing once should be faster than multiple times
    git push origin --delete $(git tag -l) 
    
  4. Delete All local tags.
    git tag -d $(git tag -l)
    
like image 122
Amir Hosseinzadeh Avatar answered Oct 05 '22 22:10

Amir Hosseinzadeh


For windows using command prompt:

Deleting local tags:

for /f "tokens=* delims=" %a in ('git tag -l') do git tag -d %a

Deleting remote tags:

for /f "tokens=* delims=" %a in ('git tag -l') do git push --delete origin %a
like image 41
npocmaka Avatar answered Oct 05 '22 22:10

npocmaka


The main answer didn't work for me.

This failed:

git push origin --delete $(git tag -l)

Error:

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

That's because I had NO local tags!

git tag -l showed nothing, even after running git fetch to supposedly fetch all remote tags!

BUT, the following worked!:

Under certain, rare circumstances, where you have remote tags on GitHub but no local tags, for instance, you may need to manually specify the tags to delete.

Go to https://github.com/YOUR_USERNAME/YOUR_REPO_NAME/tags (ex: https://github.com/ElectricRCAircraftGuy/sublime_gcode/tags) to view all remote tags.

Mine showed tags 1.0.0 and 1.0.1. Delete them manually with:

To delete remote tags manually:

# General format to delete a **remote** tag on remote named "origin"
git push --delete origin <tag_name>

# My case exactly
git push --delete origin 1.0.0
git push --delete origin 1.0.1

To delete local tags manually:

# list all tags
git tag
# OR (same thing): 
git tag -l

# delete a local tag
git tag -d <tag_name>
# Example: delete local tag named `1.0.0`
git tag -d 1.0.0

Source where I learned all of this: https://devconnected.com/how-to-delete-local-and-remote-tags-on-git/

like image 43
Gabriel Staples Avatar answered Oct 05 '22 21:10

Gabriel Staples