I'm trying to add a submodule that already existed (different git remote repository). As I didn't searched before how to do it correctly, I think I've messed up my repository and I need some help to fix it again.
I've already deleted all the relevant sections from the .gitmodules and .git/config regarding the submodules I want to delete. I've also verified that there is not modules directory inside my .git/ directory.
However, when I run the command
git rm --cached path_to_submodule
fatal: pathspec 'path_to_submodule' did not match any files
git submodule add gituser@host:repo.git
'repo' already exists in 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@example.com: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 firstname.lastname@example.org: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.