So I think the exact depth would still be a myth, which is the only and must be resolved concern of the question
While there is indeed no "exact depth", you can still record a "depth recommendation" with git 2.9.x+ (Q3 2016).
See commit abed000, commit 37f52e9 (26 May 2016) by Stefan Beller (stefanbeller
).
(Merged by Junio C Hamano -- gitster
-- in commit 3807098, 20 Jun 2016)
submodule update
: learn --[no-]recommend-shallow
option
An upstream project can make a recommendation to shallowly clone some submodules in the .gitmodules
file it ships.
Sometimes the history of a submodule is not considered important by the projects upstream.
To make it easier for downstream users, allow a boolean field 'submodule.<name>.shallow
' in .gitmodules
, which can be used to recommend whether upstream considers the history important.
This field is honored in the initial clone by default, it can be ignored by giving the --no-recommend-shallow
option.
That way, a simple git submodule update
(no additional parameters) will use the recommended depth value, if found.
See also "Git submodule without extra weight" with:
git config -f .gitmodules submodule.<name>.shallow true
g19fanatic proposes in the comments:
quick 1-liner to add shallow=true
to all submodules:
git submodule | awk '{print $2}' | \
xargs -n 1 -I %% bash -c 'git config -f .gitmodules submodule.%%.shallow true'
or, with git submodule foreach
:
git submodule foreach 'git config -f .gitmodules submodule.$sm_path.shallow true'
However, akhan adds in the comments:
The foreach
command is executed from the submodules and hence will not work as described here (try git submodule foreach 'echo $PWD'
for instance).
However the xargs
works just fine.
Working recipe:
git submodule | awk '{print $2}' | \
xargs -n 1 -I %% bash -c 'git config -f .gitmodules submodule.%%.shallow true'
git submodule update --depth=1