Search code examples
gitgit-submodules

Get "please make sure that the .gitmodules file is in the working tree" when running the git submodule add command


I'm new to git, currently looking at porting some large projects from mercurial. We have a root project that just contains the references to all the external projects (submodules in git). I'm trying to recreate this in git.

I have imported a project (foo) into githib. I've created a new empty project (root) and cloned it locally. I want to add Foo as a submodule using

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

from the /c/Work/GitHub/root (master)

but I keep getting "please make sure that the .gitmodules file is in the working tree".

Looking at the documentation, the first run of this command should create the .gitmodules file, but I get this error even if I create it by hand. Looking for this error on Google just returns the source files with the error but no explanation to why I'm getting it. I assume it's just my poor understand of git.

What I'm I doing wrong?

EDIT: I've also tried.

mkdir test
cd test
git init
git submodule add https://github.com/.../foo.git

I get the same error.


Solution

  • Just in case anyone else has this issue. There was something wrong with my git installation. I uninstalled and reinstalled it the error went away.