Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git shallow fetch of a new tag

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?

like image 753
Adam Watkins Avatar asked Oct 28 '14 20:10

Adam Watkins


People also ask

Does git fetch include tags?

git fetch --tags fetches all tags, all commits necessary for them. It will not update branch heads, even if they are reachable from the tags which were fetched.

Does git pull fetch new branches?

Pull does a fetch and then by default merges the remote tracking branch of the current branch into the current branch, whatever it may be, changing the files you can actually see.

Does git fetch change anything?

git fetch is the command that tells your local git to retrieve the latest meta-data info from the original (yet doesn't do any file transferring. It's more like just checking to see if there are any changes available). git pull on the other hand does that AND brings (copy) those changes from the remote repository.


1 Answers

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
like image 118
Ed I Avatar answered Sep 18 '22 17:09

Ed I