git: shallow clone and sparse checkout of submodule

If you have a huge repository (in size and in history) and want to add a subfolder to your project as a submodule you can follow the code in this example to save time and space using git’s shallow clone and sparse checkout feature. It is a bit more complicated in this example because I assume that you want your submodule to track a non-default branch, called `mybranch`, instead of the `master` branch. Also I assume you already have a checkout of  our huge repository somewhere, so it can be used as an argument to the --reference option of git clone. Things could probably get a lot simpler when using the default branch and just using a normal clone (with no reference  repo). After following the commands in these examples you can use `git submodule update` and `git submodule update –remote` as normal.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s