Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: push only specific tags

Tags:

git

tags

AFAIK, git push --tag pushes every tags under refs/tags to remote. I want to know if there is a way in git to only push some tags that matches a wildcard or regexp?

For example, my repo has tag v1.0, v1.1, v2.0 and v2.1. I want to only push v2.*. I tried

git push <repo> refs/tags/v2.*

and got error

fatal: remote part of refspec is not a valid name in refs/tags/v2.*

Of course, I can always do

cd .git && ls refs/tags/v2.* | xargs git push <repo>

But this does not smell gity.

like image 980
Crend King Avatar asked Feb 09 '13 02:02

Crend King


People also ask

How do I push a specific tag?

Sharing Tags You will have to explicitly push tags to a shared server after you have created them. This process is just like sharing remote branches — you can run git push origin <tagname> . If you have a lot of tags that you want to push up at once, you can also use the --tags option to the git push command.

Does git push all include tags?

Sharing: Pushing Tags to Remote Sharing tags is similar to pushing branches. 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.

Can I push to a tag?

Pushing a tag in git to a remote is similar to pushing a branch to a git remote. The only difference is that you need to mention the tag name after the "git push" command as by default this command only pushed the branch.

What is git push -- tags?

Git tags label specific commits and release versions in a Git project development. The git push command allows users to export their local commits and tags to a remote repository. In this tutorial, you will learn to create and push Git tags to a remote repository.


2 Answers

git tag | grep '^v2\.' | xargs --no-run-if-empty  git push <repo>
  • .git may not be directory, it may not be there at all. Submodules have there file pointing to root repository. Or you can have GIT_DIR set to somewhere else.
  • When no tags match your criteria, you do not want to do the push.
like image 116
Josef Kufner Avatar answered Sep 28 '22 13:09

Josef Kufner


git push <remote> tag <tag>

In your case it will be

git push origin tag v2.*
like image 32
Serg Stetsuk Avatar answered Sep 28 '22 12:09

Serg Stetsuk