Topic on Talk:Download from Git

using depth when cloning a tag

11
Berot3 (talkcontribs)

I couldn't find anything related here.

I wanted to use git to download the 1.35.1 tag but with --depth=1. I think it is workth mentioning on Download from Git#Download a stable branch that (from what I found on google) this is the command:

git clone https://gerrit.wikimedia.org/r/mediawiki/core.git --branch 1.35.1 --depth=1 mediawiki

so instead of cloning a actual branch, we can use the tag.

How did I get to this you may ask? Well when first doing:

git clone https://gerrit.wikimedia.org/r/mediawiki/core.git --branch REL1_35 mediawiki --depth=1

and than

git checkout 1.35.1

(as the page suggests) you wont get anywhere, because no tags where downloaded.

Am I missing something? Let me know please.

Berot3 (talkcontribs)

or is it so that --branch REL1_35 already is on tag 1.35.1? But than why should I checkout 1.35.1?

MarkAHershberger (talkcontribs)

Try the following:

git clone -b 1.35.1 --single-branch  https://gerrit.wikimedia.org/r/mediawiki/core.git mediawiki
MarkAHershberger (talkcontribs)

Never mind, it looks like using git to specify a single tag as the branch is the quickest and most light-weight checkout.

Checking out the entire repo and then fetching just that tag takes me about half a minute longer and 40mb more space than just checking out a single branch:

 time (
   git clone https://gerrit.wikimedia.org/r/mediawiki/core.git &&
   cd core &&
   git checkout 1.35.1
 ) && du -sh core
 ...
 user    5m11.114s
 ...
 448M    core

vs.

 time git clone -b 1.35.1 --single-branch \
   https://gerrit.wikimedia.org/r/mediawiki/core.git &&
 du -sh core
 ...
 user    4m40.874s
 ...
 407M    core

But your method is fast and cheap.

 time git clone -b 1.35.1 --depth 1 \
   https://gerrit.wikimedia.org/r/mediawiki/core.git &&
 du -sh core
 ...
 user    0m2.076s
 ...
 174M    core
Berot3 (talkcontribs)

Thanks, but I just googled ;)

Did you maybe see my second question? I’m a bit confused, if just clone the branch, am I already on 1.35.1? If so than I could also clone the branch with depth=1.

MarkAHershberger (talkcontribs)

A branch is not the same as a tag. Commits can be on a branch after the revision tagged 1.35.1. If you want 1.35.1, it is best to directly check it out.

Berot3 (talkcontribs)

so as I thought, on both (-b 1.35.1 and -b REL1_35) I am greeted with the initial setup for 1.35.1.

Sure, as you said, if you really want the exact version from the release-date, use the tag. But I guess when I stay on the branch REL1_35 and there comes version 1.35.2 around, I will probably only have to run git pull --recurse-submodules to get the latest code.

Berot3 (talkcontribs)

but that is my problem with the page: it suggest using --depth=1 (with -b REL1_35), but when doing so, I can not later git tag -l | sort -V and git checkout 1.35.1.

The text needs to be written like that: If you want clone a tag (1.35.1) AND use --depth=1 you have to clone it directly with -b 1.35.1.

Or am I totally in the wrong here?

MarkAHershberger (talkcontribs)

Last night I had to pull get branches for a shallow clone, so I ended up looking for the answer.

The answer is that you have to tell git where to get branches from:

 git remote set-branches origin '*'
 git fetch

After that, you'll be able to check out branches from a repo that you originally created with a shallow clone.

Berot3 (talkcontribs)

well at first I think we are talking about two different problems:

  1. Problem: is it better to use branches (REL1_35) or tags (1.35.1). I think we should at first clarify on the article that a: there are two ways to clone the stable branch/tag and b: it is recommended to always clone the current stable tag instead of the branch. Would you agree? So when 1.36 comes along, it would be better to clone --branch 1.36 instead of REL1_36 (i still find it confusing that --branch is used for branches and tags qually. that means you can't have a tag with the same name as a branch, right?)
  2. Problem: use of depth It is not clear from the description of the page that you can't use git tag -l | sort -V after you cloned with depth=1! So I would explain it in a way that you either clone without depth and than be able to switch tags or use depth=1. of course (thanks for that) here is your command coming in handy (when cloned with depth=1) git remote set-branches origin '*' git fetch

Did I miss something? :)

MarkAHershberger (talkcontribs)
i still find it confusing that --branch is used for branches and tags qually. that means you can't have a tag with the same name as a branch, right?
I hadn't thought about it, but I think you're right.
Did I miss something?
I think you've got it.
Reply to "using depth when cloning a tag"