Search code examples
gitgit-submodulesgit-statusgit-track

Git repo with submodules does not track local changes?


I have a git repository with 3 submodules, like this:

foo/  # main repository
  bar1/  # submodule1
  bar2/  # submodule2
  bar3/  # submodule3

I've added the submodules directly after executing git init in the main repository:

git submodule add https://github.com/bar1.git bar1
...

The strange thing now is if I add a new directory like foo/test/ git does not track changes inside of foo/test/. Just changes directly inside of foo/ are tracked or changes to the submodules. Why is that?

It appears to me like git is treating foo/test like a submodule, while it is certainly not.

The .gitignore looks like this:

.idea/

...which basically only ignores the hidden IDE project-related dir.

.gitmodules looks like this:

[submodule "bar1"]
path = bar1
url = https://github.com/...

[submodule "bar2"] path = bar2 url = https://github.com/... [submodule "bar3"] path = bar3 url = https://github.com/...

Do I have to manually tell git that foo/test/ should remain inside of the main repository and that it is not a submodule?


Solution

  • I've just found the problem. I do not know why, but my git-config was messed up.

    Doing a simple git config --list (inside of foo/) revealed that core.worktree was wrong:

    core.worktree=../../../bar1
    

    I can not remember altering the config manually. I've just cloned a fresh copy of my repository, updated the submodules and copied my new changes foo/test/ into the freshly cloned repo. Now everything works.

    I guess the only question is how I could have messed up the git config of the "old/bugged" repo by mistake...