Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git submodule add fatal: Not a Git Repository

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.

like image 396
Brandon Grossutti Avatar asked Apr 06 '12 20:04

Brandon Grossutti


3 Answers

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.

like image 97
VonC Avatar answered Nov 18 '22 11:11

VonC


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.

like image 28
logicOnAbstractions Avatar answered Nov 18 '22 12:11

logicOnAbstractions


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

like image 3
Anshu Meena Avatar answered Nov 18 '22 12:11

Anshu Meena