Search code examples
gitgit-submodules

Ignoring GIT Submodule Locally


I have a project like this:

main_module
-folder
--submodule_pub1
--submodule_pub2
--submodule_sec

Not everyone reaches the submodule_sec. Is there a way for this people to check out the main_module and all public submodules, but remove the submodule_sec but only locally? With somehow mark it locally unchanged?

I have found this answer: https://stackoverflow.com/a/1260982/337621 My problem, that I do not want to make a commit, and I do not want to have the removed submodule as untracked change. Is there a way to do this? Which commands do I need for the example above?


Solution

  • You can try, with recent git 1.8.3+, a:

    git submodule deinit -- folder/submodule_sec
    

    From the git submodule man page:

    Further calls to git submodule update, git submodule foreach and git submodule sync will skip any unregistered submodules until they are initialized again,

    Since it unregisters a submodule, removing it from the .git/config file, that means it is only a local modification of the local config: it doesn't affect the submodule itself, which continues to be referenced by the parent repo, both in the working tree and in the .gitmodules files.
    But the git submodule update command won't initialize and checkout a submodule that you just deinit.