git submodule add fatal: Not a Git Repository
Asked Answered
L

3

11

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.

Lavonia answered 6/4, 2012 at 20:18 Comment(3)
did you try createing the externalsource directory and then cd'ing to it and adding the submodule?Pleasantry
i did and when adding a submodule you have to do so from the root directory was the error backLavonia
You have a slash at the end of JOliverEventStore in the original command. Perhaps git is too stupid to think that you want to checkout to JOliverEventStore below the directory JOliverEventStore (which does not exists)?Margheritamargi
M
12

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.

Mandrake answered 7/4, 2012 at 9:36 Comment(4)
Thanks vonc. I saw that article too. An update is prolly in order. I didn't see if it was resolved in last release though. It seems like such a common task I was surprised to see the issueLavonia
Upgrading from git 1.6.x (included with Mountain Lion) to 1.8.1 fixed the problem.Parang
The bug was not the cause of me seeing the same error message. My repo's location had changed, and I needed to update git's configuration files: #10144649Carden
@Carden good to know. I have included your comment in the answer for more visibility.Mandrake
C
9

This will seem silly, but since I just wasted 30 minutes on that stupid mistake....

You parent repository must have already been created as git repository. I had just created the parent, then I created the submodule and & tried to git submodule add into the parent. However, the parent hadn't been initialized as a git repo.

This resulted in the same error as the one you mentioned ("not a git repository"). However it was the parent which wasn't a git repository.... silly.

Cypro answered 23/7, 2020 at 14:57 Comment(0)
M
5

i wasted several minutes just for a simple problem

first git init

and then install theme git submodule add https://github.com/joliver/EventStore.git JOliverEventStore

Mom answered 25/6, 2021 at 16:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.