Forked from kouk/How to add a submodule with shallow checkout and shallow clone
Created
July 12, 2017 16:22
-
-
Save nfultz/4139d46f62254bca18cb9efd22e908ea to your computer and use it in GitHub Desktop.
.How to add a submodule with shallow checkout and shallow clone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 this example to save time and space | |
using git's shallow clone and shallow 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. Things could probably get | |
a lot simpler when using the default branch. After following the commands in these | |
examples you can use `git submodule update` and `git submodule update --remote` as normal. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git clone --depth 1 --reference ../path/to/mymodcheckout -n --separate-git-dir $gitdir -b mybranch [email protected]:user/repo mymod | |
$ git submodule add [email protected]:user/repo mymod | |
$ git config submodule.mymod.branch mybranch | |
$ git config submodule.mymod.update '!../update.sh' | |
$ (cd mymod; ../update.sh) | |
$ git commit -m "add submodule mymod" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git submodule init mymod | |
$ git config submodule.mymod.branch mybranch | |
$ git config submodule.mymod.update '!../update.sh' | |
$ gitdir=$(git rev-parse --git-dir)/modules/mymod | |
$ git clone --depth 1 --reference ../path/to/mymodcheckout -n --separate-git-dir $gitdir -b mybranch [email protected]:user/repo mymod | |
$ (cd static && ../update.sh) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# alternative to the --checkout option for `git submodule update` | |
# sets up shallow checkout of the `MyMod` directory in the repo | |
S=$(git rev-parse --git-dir)/info/sparse-checkout | |
echo /.gitignore > $S | |
echo /MyMod >> $S | |
git config core.sparsecheckout true | |
git checkout $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment