git submodule add fatal: Not a Git Repository

git, git-submodules

Solution

It can depends on the version of Git you are using: this recent thread (February 2012) mentions a bug:

Since recently a submodule with name `<name>` has its git directory in the `.git/modules/<name>` directory of the superproject while the work tree contains a `gitfile` pointing there.

When the same submodule is added on a branch where it wasn't present so far (it is not found in the .gitmodules file), the name is not initialized from the path as it should. This leads to a wrong path entered in the `gitfile` when the `.git/modules/<name>` directory is found, as this happily uses the - now empty - name. It then always points only a single directory up, even if we have a path deeper in the directory hierarchy.

But more generally, uses the `<path>` argument of `git submodule`:

`<path>` is the relative location for the cloned submodule to exist in the superproject.

- If `<path>` does not exist, then the submodule is created by cloning from the named URL.

- If `<path>` does exist and is already a valid git repository, then this is added to the changeset without cloning. This second form is provided to ease creating a new submodule from scratch, and presumes the user will later push the submodule to the given URL.

eoinoc mentions in the comments another cause, which is detailed in the question "`git status` returns `fatal: Not a git repository but .git exists and HEAD has proper permissions`".

My repo's location had changed, and I needed to update git's configuration files.

Problem

I am fairly new to Git and trying my best to find some documentation on this problem to no avail. Here's my command: ``` $ git submodule add https://github.com/joliver/EventStore.git externalsource/JOliverEventStore/ ``` fatal: Not a git repository: ../.git/modules/externalsource/JOliverEventStore Unable to checkout submodule 'externalsource/JOliverEventStore' I am in my root of my repo and there is currently no directory for `/externalsource/JO liverEventStore/`. The error is talking about a directory that I have no knowledge of. If I add the submodule to the root dir like this: ``` $ git submodule add https://github.com/joliver/EventStore.git JOliverEventStore ``` I have no problem and it creates the folder in the root directory. Any insight would be greatly appreciated.

Original source

Related problems