Git shallow fetch of a new tag
Asked Answered
R

1

20

If I clone a repository with max depth of 1 at a tag, it works and pulls down just that. If I then want to do a fetch with or without depth of 1 for a new tag, it does some processing, but the tag never shows up under 'git tag'. If I supply the --tags option, it downloads the whole repository rather than just the new information. I don't mind the repository getting more history, I just want to avoid the download times. Is there any way to get a new tag without getting all tags from a shallow cloned repository?

git clone --branch 1.0 --depth 1 repositoryPath
git fetch --depth 1 origin tags/1.1 # Does processing but no new tags
git fetch --tags origin tags/1.1 # Pulls down the rest of the repository and adds all tags
git fetch --depth 1 --tags origin tags/1.1 # Same as above

Now, I have noticed this in the documentation: "--depth ... Tags for the deepened commits are not fetched."

Is this what I'm running into? Is there no way to do this besides downloading all tags?

Repentance answered 28/10, 2014 at 20:26 Comment(0)
S
27

You can use the full <refspec> format:

git fetch --depth 1 origin refs/tags/1.1:refs/tags/1.1

Or, as specified in git-fetch options (under <refspec>):

tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>; it requests fetching everything up to the given tag.

So the short form answer to your question would be

git fetch --depth 1 origin tag 1.1
Sectarianize answered 28/10, 2014 at 22:3 Comment(1)
Awesome, that did it. I didn't read the refspec thoroughly enough. I imagined you just had to put a path, not remote:local. I guess the confusing part is it kindof worked as in it did something... ThanksRepentance

© 2022 - 2024 — McMap. All rights reserved.