When we have many (say 20) submodule in a git repository, we can install (and update) them like so:
git submodules update --init --recursive
Git tries to download every submodule (recursively) after this command. What if we want to make some of the submodules optional (like a plugin)?
How can we make git skip downloading these optional submodules by default and handle as a usual submodule when we mark this submodule "okay, use this from now on"?
Pulling with submodules. Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .
One way to do this would be to :
To get the list of submodules and format it to display only submodule path :
git submodule--helper list | awk '{$1=$2=$3=""; print substr($0,4)}'
To exclude a submodule X :
git -c submodule."X".update=none submodule update --init --recursive
Combining these two commands with xargs and tr utilities and further using command substitutition,
git $(git submodule--helper list | awk '{$1=$2=$3=""; print substr($0,4)}' | xargs -pI % echo -c submodule.\"%\".update=none | tr '\n' ' '| xargs echo) submodule update --init --recursive
The interactive mode of xargs util allows user to select which submodule to update i.e by supplying input in (y/n)
format. Input y
indicates that submodule is excluded during the update. Input n
indicates no action is taken.
Note:
The submodule name here is assumed to be the same as it's path. However, have a look here to get submodule names with diverging names and paths.
To exclude or include the submodule X (permanently), the attribute submodule."X".update
should be added to the gitconfig file for the local repo. For exclusion set submodule."X".update
to none
in the config file by using this command
git config --local submodule."X".update none
and for inclusion unset it by using this command
git config --local --unset submodule."X".update
For excluding nested submodules, follow this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With