Search code examples
gitconfiggit-submodules

How to get git includeIf work for submodule


[core]
    editor = \"C:\\Microsoft VS Code\\bin\\code\" --wait

[includeIf "gitdir/i:D:/code/project/"]
   path = project.gitconfig

[includeIf "gitdir/i:D:/code/project/acts/ccxt/ccxt"] # not working, why?
    path = github.submodule.gitconfig

[includeIf "gitdir/i:E:/code/project/"]
    path = project.gitconfig

[includeIf "gitdir/i:d:/OneDrive/code/"]
    path = project.gitconfig

[includeIf "gitdir/i:D:/code/github/"]
    path = github.gitconfig

D:/code/project/acts/ccxt/ccxt is a submodule of D:/code/project/acts/. All includeIf work except the one in the submodule. If I comment out D:/code/project/acts/ and change D:/code/project/acts/ccxt/ccxt to D:/code/project/acts/ it works, but I need different settings for ccxt and project.


Solution

  • Typically a git repository will have its config located in .../repository/.git/config. In a submodule, that configuration is not actually located in the submodule's .git directory, it's located in the parent repository's .git directory.

    In your case, the parent repository is D:/code/project/acts/, so your submodule's config directory is actually located in D:/code/project/acts/.git/modules/ccxt/ccxt/config. This means that your includeIf should look like this:

    [includeIf "gitdir/i:D:/code/project/acts/.git/modules/ccxt/ccxt"]
        path = github.submodule.gitconfig