Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 377
Carl Björknäs Avatar asked Aug 14 '17 18:08

Carl Björknäs


People also ask

Does git push push all tags?

By default, git push will not push tags. Tags have to be explicitly passed to git push . To push multiple tags simultaneously pass the --tags option to git push command.

How do I stop git push?

The trick to prevent accidentally pushing in-development changes to the wrong environment is to use the git command for changing remote's URL. By adding the --push flag to the command, only the push URL is manipulated. So it is still possible to pull from that remote.

What does push all tags mean in git?

The new " --follow-tags " option tells " git push " to push relevant annotated tags when pushing branches out. You can now try, when pushing new commits: git push --follow-tags. That won't push all the local tags though, only the annotated ones referenced by commits which are pushed with the git push .


1 Answers

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.

like image 188
Marina Liu Avatar answered Nov 15 '22 20:11

Marina Liu