Skip to content

Instantly share code, notes, and snippets.

@RandomArray
Last active May 26, 2022 23:19
Show Gist options
  • Save RandomArray/fdaa427878952d9768b0 to your computer and use it in GitHub Desktop.
Save RandomArray/fdaa427878952d9768b0 to your computer and use it in GitHub Desktop.
Replace with your own usename and email:
------------------------------------------------
git config --global user.name "Username"
git config --global user.email "[email protected]"
These next two commands tell Git to use your Windows credentials to store your origin password.
------------------------------------------------
git config --global credential.helper wincred
git config --global credential.helper store
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
This deletes all Remote/Origin Tags from the list output by "git tag -l".
------------------------------------------------
FOR /f "tokens=*" %a in ('git tag -l') DO git push --delete origin %a
I had to run the 1st command a second time for "git tag" to not list tags anymore.
@RandomArray
Copy link
Author

Remove All Git Tags with the Windows Command Line

Windows CLI commands to delete all GIt Tags and then remove the tags from origin. Use at your own risk.

These first few commands will stop Git from asking for your password to origin throughout the loop.

Replace with your own usename and email:

git config --global user.name "Username"
git config --global user.email "[email protected]"

These next two commands tell Git to use your Windows credentials to store your origin password.

git config --global credential.helper wincred
git config --global credential.helper store

Git Tag Destruction:

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

This deletes all Remote/Origin Tags from the list output by "git tag -l".

FOR /f "tokens=*" %a in ('git tag -l') DO git push --delete origin %a

I had to run the 1st command a second time for git tag to not list tags anymore.

I am just learning Git and I cloned a some random jquery-upload-??? project. I noticed all of the other project's commit logs showing up in the project I was working on. I could not find a way inside of Git Gui or SourceTree to remove the other Repo/Project/?? from my project. None of the files existed, and the other project wasn't listed anywhere. Just the commits were showing up. I see how this could be a good thing once I figure it out. The commands above were the only way I could quickly clean up the mess I made for myself.

When I ran the Linux commands from Git Bash on Windows, they did not work. I got the following errors:

X:\user1>git tag | xargs git tag -d
xargs: cannot fork: Permission denied
X:\user1>git tag -l | xargs git tag -d
xargs: cannot fork: Permission denied
X:\user1>git tag -l | xargs -n 1 git tag -d
xargs: cannot fork: Permission denied   

More searching led me to discover that since I was on Windows, I needed to do the same thing xargs was doing, but with a Windows command. I've included the links where I found some information that helped me get to this point.

http://stackoverflow.com/questions/19542301/delete-all-tags-from-a-git-repository/19542426#19542426

http://superuser.com/questions/276373/is-it-possible-to-pipe-a-list-of-files-to-rmdir-on-windows

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