How do you push a tag to a remote repository using Git?

前端 未结 9 861
滥情空心
滥情空心 2020-11-22 16:31

I have cloned a remote Git repository to my laptop, then I wanted to add a tag so I ran

git tag mytag master

When I run git tag

相关标签:
9条回答
  • 2020-11-22 17:08

    You can push all local tags by simply git push --tags command.

    $ git tag                         # see tag lists
    $ git push origin <tag-name>      # push a single tag
    $ git push --tags                 # push all local tags 
    
    0 讨论(0)
  • 2020-11-22 17:09

    To push specific, one tag do following git push origin tag_name

    0 讨论(0)
  • 2020-11-22 17:10

    I am using git push <remote-name> tag <tag-name> to ensure that I am pushing a tag. I use it like: git push origin tag v1.0.1. This pattern is based upon the documentation (man git-push):

    OPTIONS
       ...
       <refspec>...
           ...
           tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>.
    
    0 讨论(0)
  • 2020-11-22 17:15

    How can I push my tag to the remote repository so that all client computers can see it?

    Run this to push mytag to your git origin (eg: GitHub or GitLab)

    git push origin refs/tags/mytag
    

    It's better to use the full "refspec" as shown above (literally refs/tags/mytag) just in-case mytag is actually v1.0.0 and is ambiguous (eg: because there's a branch also named v1.0.0).

    0 讨论(0)
  • 2020-11-22 17:18

    You can push the tags like this git push --tags

    0 讨论(0)
  • 2020-11-22 17:20

    git push --follow-tags

    This is a sane option introduced in Git 1.8.3:

    git push --follow-tags
    

    It pushes both commits and only tags that are both:

    • annotated
    • reachable (an ancestor) from the pushed commits

    This is sane because:

    • you should only push annotated tags to the remote, and keep lightweight tags for local development to avoid tag clashes. See also: What is the difference between an annotated and unannotated tag?
    • it won't push annotated tags on unrelated branches

    It is for those reasons that --tags should be avoided.

    Git 2.4 has added the push.followTags option to turn that flag on by default which you can set with:

    git config --global push.followTags true
    

    or by adding followTags = true to the [push] section of your ~/.gitconfig file.

    0 讨论(0)
提交回复
热议问题