Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude a specific git submodule from update?

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"
like image 416
Prasha Avatar asked Sep 05 '18 07:09

Prasha


People also ask

How do you update a specific submodule?

In order to update an existing Git submodule, you need to execute the “git submodule update” with the “–remote” and the “–merge” option. Using the “–remote” command, you will be able to update your existing Git submodules without having to run “git pull” commands in each submodule of your project.

How do I ignore changes in git submodules?

Another method is to use the swicth --ignore-submodules=dirty of git status (available from git version 1.7. 2) and create an alias to shorten the typing. Ignore changes to submodules when looking for changes. can be either "none", "untracked", "dirty" or "all", which is the default.

How do I checkout a specific commit of a submodule?

Use the git submodule update command to set the submodules to the commit specified by the main repository. This means that if you pull in new changes into the submodules, you need to create a new commit in your main repository in order to track the updates of the nested submodules.


1 Answers

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
like image 198
kabanus Avatar answered Oct 24 '22 04:10

kabanus