Carl Björknäs Carl Björknäs -3 years ago 130
Git Question

How do I stop users from pushing all tags (git push --tags)?

We created lots of tags before we discovered that git tags can be named with slashes to get them arranged in a folder structure. Now it is really hard to get rid of the misnamed tags, because although I delete the misnamed tags on the server, suddenly someone that haven't deleted their tags locally pushes all tags and then both old and new tags are on the server again.

We're using SourceTree as git client (and yes, I've been around and made sure that everyone have unchecked the "push all tags" checkbox, but new people arrive and computers are replaced) and Visual Studio Team Services Git repo.

I want everyone to be able to create and push tags individually, I just want to avoid those bulk pushes of tags.

I've read this post git pre-push hook, don't run if is --tags but the solution doesn't seem to work in Windows.

Answer Source

No matter git hooks or other scripts, all of them need to run on the local machines individually. So I will suggest to sync tags with remote before the developers create their own tags on local machines.

Actually it just need to execute once for each local machine, so the developers just need to run below commands (delete local tags and get all tags from remote) on their machine before working:

git tag -l | xargs git tag -d
git fetch --tags

Then the developers can work on their own local repo and even git push with push all tags option selected in SourceTree won’t effect the old tags you deleted.

Additional, when the server side hooks will available in future for VSTS, you can also use post-push hooks to check if the deleted tags are pushed to remote again. If yes, stop to push the certain tag(s) you specified in post-push hook.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download