Add a submodule which can't be removed from the index

The only way that message ('repo' already exists in the index) can be displayed is if 'repo' still exists in the index (see this chapter on submodule):

$ rm -Rf rack/
$ git submodule add [email protected]:schacon/rack.git rack
'rack' already exists in the index

You have to unstage the rack directory first. Then you can add the submodule:

$ git rm -r rack
$ git submodule add [email protected]:schacon/rack.git rack

Even if 'rack' isn't a submodule, if it exists, it would prevent the declaration of a submodule of the same name.


If the output adding a new submodule is:

'FolderName' already exists in the index

Tip the next commands

git ls-files --stage 

The output will be something similar to:

160000 d023657a21c1bf05d0eeaac6218eb5cca8520d16  0  FolderName

Then, to remove the folder index tip:

git rm -r --cached FolderName

Try again add the submodule


May occur, when merging with error, manual deleting of folder of submodule, or something else, like Hallileo Comet

  1. in file .gitmodules - delete links to submodule (whole section with submodule name)

  2. in file .git\config - delete links to submodule, as in previous step

  3. in folder .git\modules - delete folder with relative path similar to relative path of "problem" module

  4. ensure, that folder of submodule is not exists anymore

  5. then:

    $ git submodule add -f --name <name> <git://path_1.git> <path_2>

    where: name - name of submodule as u wish, may be equal your repo name; - path to submodule source repo (ie - github, etc), - relative path to folder where submodule will reside

    this lets u to add submodule within path or with name which still present in index, but not naturally alive.

i didn't found any method to remove these dead links from index, but when forced