22

I have list of submodules in .gitmodules. I want to download a specific submodule i.e grpc only if there is some option enabled as true in config file. Since grpc is not required at times for my build. All submodules are in third-party directory. So .gitmodules is like:

[submodule "third-party/libzip"]
        path = third-party/libzip
        url = https://github.com/nih-at/libzip.git
[submodule "third-party/sqlite"]
    path = third-party/sqlite
    url = https://github.com/mackyle/sqlite.git
    branch = sqlite-3.23.1
[submodule "third-party/grpc"]
    path = third-party/grpc
    url = https://github.com/grpc/grpc.git

Also is there a way to exclude the submodule specifically while executing command:

git submodule update --init --recursive

I would like to exclude grpc and submodules in grpc while submodule update. Something like:

git submodule update --init --recursive "exclude third-party/grpc"
Prashant Shubham
  • 456
  • 8
  • 20
Prasha
  • 371
  • 1
  • 3
  • 13
  • 1
    This might be an [XY](http://xyproblem.info/) question. Why do you want to exclude the sub-module? – kabanus Sep 05 '18 at 07:35
  • 1
    @kabanus since the submodule is not required during build at times. I don't want to update --init a submodule which is not needed if it's config is set to false. – Prasha Sep 05 '18 at 11:42

1 Answers1

24

From the git help:

update

Update the registered submodules to match what the superproject expects by cloning missing submodules and updating the working tree of the submodules. The "updating" can be done in several ways depending on command line options and the value of submodule..update configuration variable. Supported update procedures are:

...

...

When no option is given and submodule.<name>.update is set to none, the submodule is not updated.

So set update = none in the configuration file. You can also explicitly give paths after -- to only update specific submodules. To do this on the fly and not change your configuration file, @PrashantShubham notes you can:

git -c submodule."third-party/grpc".update=none submodule update --init --recursive
kabanus
  • 24,623
  • 6
  • 41
  • 74
  • 6
    Please update Complete command: `git -c submodule."third-party/grpc".update=none submodule update --init --recursive` – Prashant Shubham Sep 06 '18 at 13:58
  • @PrashantShubham Thanks, though actually I was suggesting he put it in the configuration file directly (see the original post, adding a line there directly). But you are welcome to add an answer how to do it from the shell, or suggest an edit to my answer (you get +2 rep for every accepted suggestion). – kabanus Sep 06 '18 at 15:22
  • Any idea how you can get this working for a submodule of a submodule when using also the --recursive option? – Zatarra Nov 19 '19 at 13:16
  • @Zatarra Listing the inner submodule in `-c submodule."inner".update=none` works for me. Probably changing the config file for the inner submodule would do the same. – kabanus Nov 19 '19 at 18:49
  • I just wanted to post an observation that may not immediately be obvious: If you run `git config submodule..update none` before running `git submodule update --init --recursive`, the second command will ignore the first. The only time it works is as this answer describes which is to combine both commands into one. HTH – smac89 Dec 17 '20 at 03:09