checkout commit with different submodule setup does not work properly

In one of our git repo, there was a submodule added at some point. Now, whenever I checkout a state of the git repo, where the submodule was not yet there it does not properly “remove” the submodule. It seems to be in a state, where the submodule is half there, half not.

I also noticed, that the submodule is no longer preset in .gitmodules but its folders in path/to/submodule and in .git/modules still exist.

I tried at least the following things:

git status => Untracked files: path/to/submodule

git reset --hard => unchanged

git submodule foreach reset --hard => unchanged

git clean -d -f => Skipping repository path/to/submodule

git submodule update --init => unchanged

But until now I did not get it solved. Of course I could manually delete these folders, but I want it to work automatically, when I switch commits, as this is also an issue on our CI (Jenkins).

Any help / hint is highly appreciated!

  • Configure depth of git submodule
  • Git change the repo path of a subfolder
  • Run brunch from different directory and use relative paths
  • Git submodules: specify a specific SHA?
  • Will deleting a branch in a git submodule's repository make commits in that branch unavailable to the superproject?
  • different push/pull urls for git submodule
  • How does git handle cloning another repository into a subdirectory?
  • How to automatically download the same 8 repos for every from another 4 repos in a git?
  • One Solution collect form web for “checkout commit with different submodule setup does not work properly”

    You need to run git clean with double -f arguments. From the documentation (emphasis mine):


    If the Git configuration variable clean.requireForce is not set to
    false, git clean will refuse to delete files or directories unless
    given -f, -n or -i. Git will refuse to delete directories with .git
    sub directory or file unless a second -f is given.
    This affects also
    git submodules where the storage area of the removed submodule under
    .git/modules/ is not removed until -f is given twice.

    So the correct command is: git clean -d -f -f

    Git Baby is a git and github fan, let's start git clone.