1

Say that I have a repo A, that has a submodule B. B has a branch X that A is interested in. Is it possible to clone A, and then get branch X for B, without also pulling down B's master. I tried having .gitmodule specify branch X for B, "git submodule update --single-branch -- path_to_B", changing submodule fetch refspec to include the branch X only, but seems that B's master always gets pulled. Is it possible to not get master branch of B when cloning repo A?

Frank An
  • 11
  • 1
  • 1
    Submodules actually use detached-HEAD mode, and ideally they'd clone only the specific commit(s) needed, but some servers won't server arbitrary commits by raw hash ID, so in the general case `git submodule update --init`, which creates the clone, has to use some branch name(s). Since the superproject doesn't call for commits *by* branch names, but rather by hash ID, your best bet is always to just clone the entire submodule as a full clone. – torek Mar 15 '22 at 08:54
  • 1
    The base problem here is that *neither you nor Git* know which branch and/or tag names are needed so that your clone will contain the desired hash ID so that the superproject Git can check out that particular commit *in* that submodule *as* a detached HEAD. In the special case that you (the human) *do* know, you can just do the clone yourself manually. – torek Mar 15 '22 at 08:55

0 Answers0