简体   繁体   中英

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.

  • However this does not fetch tags which are currently on feature/blabla .
  • A git fetch only (supposed the branch is checkedout) fetches the tags too.

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.

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 --all still fetches all tags.

So the behavior must have change,d 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:

  • fetch tags in a separate local clone
  • check locally for each imported tag if they are referencing a branch
  • fetch that single tag from the separate local clone to your original local cloned repository.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM