One way to do this would be to :
- Get the list of submodules for the repo
- Get user input for each submodule (whether to update or not)
- Exclude the submodules selected by the user and,
- Update the submodules
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