Do git tags get pushed as well?

前端 未结 5 1685
青春惊慌失措
青春惊慌失措 2020-11-29 16:27

Since I created my repository it appears that the tags I have been creating are not pushed to the repository. When I do git tag on the local directory all the t

5条回答
  •  自闭症患者
    2020-11-29 16:36

    In default git remote configuration you have to push tags explicitly (while they are fetched automatically together with commits they point to). You need to use

    $ git push  tag 
    

    to push a single tag, or

    $ git push  --tags
    

    to push all tags (or git push --tags to push to default remote, usually origin).

    This is very much intended behavior, to make pushing tags explicit. Pushing tags should be usually conscious choice.


    Summarizing what Junio C. Hamano wrote (linked in comments by @Andre Miras)

    When fetching, you are interacting with a remote repository somebody has published, which means:

    1. the set of tags that exist there are all the publisher wanted people to see, and
    2. not only you but other people will also see the same tags.

    In other words, tags in repositories you fetch from are designed to be public and shared. It will facilitate communication between developers if it is easy for everybody to fetch these same tags.

    That's why git fetch automatically "follows" tags, i.e. it downloads tags when downloading revisions they point to - in other words downloads all relevant published tags.

    When pushing, you are pushing from your working repository, which most of the time is not public, and tags in that repository is not designed to be public. You can use your own local tags to mark your progress, so it does not make sense to blindly push all tags in your repository to the repository you are pushing to publish your changes, whose tags are by definition public.

    That's why you need to push tag explicitly, to mark tag as public.


    Alternatively you can configure the remote you push to to always push all tags, e.g. put something like that in your .git/config:

    [remote "publish"] # or whatever it is named
        url = ...
        push = +refs/heads/*:refs/heads/*
        push = +refs/tags/*:refs/tags/*
    

    This means force push all heads (all branches) and all tags (if you don't want force pushing of heads, remove '+' prefix from refspec).

提交回复
热议问题