Error with git: " already exists and is not a valid git repo" Error with git: " already exists and is not a valid git repo" git git

Error with git: " already exists and is not a valid git repo"


In case someone else had a similar case as mine and was struggling with this as I was because of a stupid reason:

Check if for any reason the file doesn't already exists (I had a failed git subomdule add previously)

So in the context of the question rm the file:

rm -rf libs/OAuth/functions

And then try to re add


Even if the folder doesn't exist, check the index status:

cd libs/OAuthgit ls-files -- functions

If there is an entry registered in the index, you will need to remove it before being able to add your subrepos as a submodule.
(as explained in "Issue with adding common code as git submodule: “already exists in the index”")

All this assumes that you are at the root folder of a currently cloned repo, which will act as the parent repo of any submodule you would declare.


If you have tried and failed to add a submodule multiple times, this might cause errors when trying to add it correctly.

Firstly, ensure that the dir you are adding the submodule to does not exits.
Secondly, check your .git dir.I had multiple dirs left in .git/modules/ that were causing issues.

After deleting these i were able to add the submodule to the specified dir as expexted.