16

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?

Adam Watkins
  • 195
  • 1
  • 8

1 Answers1

22

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
Ed I
  • 7,008
  • 3
  • 41
  • 50
  • 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... Thanks – Adam Watkins Oct 29 '14 at 14:11