Git submodule and shallow clones

This tip is more for my records because I am having to look up this information since it is not something I use all the time.    However, I hope it helps some of you too.  You do need a recent version of git.

If you have a submodule that has a REALLY large history and you only need the current head to build; do a simple:

git submodule init
git submodule update --depth 1

To clone to specific commit; you can do:
git submodule init
cd submodule_folder
git fetch --depth=1 origin COMMIT_ID
cd ..
git submodule update

To clone a specific tag:
git submodule init
cd submodule_folder
git fetch --depth 1 origin refs/tags/TAG_NAME
cd ..git submodule update

Hopefully these will save you (& me) some time in the future.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.