gitgit-refspec

Git fetch tags only on a specific branch?


I am using

git fetch origin feature/blabla

to be really specific what I want to fetch.

Is it possible to use my version and also fetch the tags along? (I dont want to fetch all tags with git fetch --tags). Especially this is usefull when on another branch.


Solution

  • Check first if adding --tags does import all tags.

    As seen in git/git commit 5328456, the git fetch man page used to say:

    By default, tags are auto-followed.

    This means that when fetching from a remote, any tags on the remote that point to objects that exist in the local repository are fetched.

    So if you fetch only one branch, only the tags referring that branch should be fetched.

    The OP Gabriel reports in the comments that:

    git fetch --tags --prune --prune-tags origin feature/blabla
    

    Although it does not work, since --tags still fetches all tags.

    So the behavior must have changed, and tags are no longer auto-followed.
    Git would have to consider each tag, in order to check if it contains (reference a commit of) the branch you want to fetch.
    That would delay considerably the fetch operation itself.

    So for now, --tags (meaning refs/tags/*) is the only option.

    Or a convoluted script which would: