tags:

views:

433

answers:

1

Hello everyone
I'm trying to add a submodule to my git repo, and Im getting this error in return:

remote origin does not have a url defined in .git/config

any ideas about what this might be?
I tried googling for it but only one vague link comes up

I'm doing this:

git submodule add ../extern/Lib1 lib  

I'm expecting this to create a submodule lib/Lib1
I'm aware that this will only create a reference and that I then have to update/init (not crystal clear on this part, havent gotten that far)
Its obvious that I'm just learning the submodule command.

Thank you

+6  A: 

Does ../extern/Lib1 refer to a Git repository?
If it does not, Git wouldn't know how to had the Git repo url to its .gitmodule
Also, try:

  • with the destination lib not already existing (even empty)
  • with an absolute path instead of a relative path (you can use a relative one, but just in case, it is worth a try here)

Some good sources on submodules are:


Since only the absolute path works here, it means the relative path need a reference to be compared against.
That reference is the "remote origin" which should be in your DirName/NewRepo_withSubmodules/.git/config file, like so:

$ cat .git/config
    ...
    [remote "origin"]
    url = /path/to/DirName/NewRepo_withSubmodules/.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    ...

If you do have that section in ../DirName/NewRepo_withSubmodules/.git/config file, you should be able to add ../Extern/Lib1 as a submodule using a relative path.

All the above is inspired from the following section of the git submodule man page:

<repository> is the URL of the new submodule's origin repository.
This may be either an absolute URL, or (if it begins with ./ or ../), the location relative to the superproject's origin repository.

So if NewRepo_withSubmodules is a local Git repo which has just been created (and has of course no "origin"), an artificial "remote origin" ought to be defined (even if the origin points to itself), if only to allow relative url for other submodule repositories to be used.

VonC
yep it does. the ./lib folder is empty tho (in "git submodule add ../extern/Lib1 lib")
deepblue
damn. ok, so the absolute path worked, the relative does not... this is not mentioned anywhere (I've been reading tutorials for hours and they all use web URL's as examples). the problem with this is when someone else clones my repos, and does not have the correct dir nesting, the 'submodule init/update' wont work for them... any ideas?thanks Von, appreciate it
deepblue
deepblue
Good question, which made me revisit the `.git/config` file location. See my edited answer.
VonC
thanks for your time Vic. Im giving it all a shot right now. will approve the answer as the final one when it all goes through in my test setup.
deepblue
great! so it worked. in order to use relative paths to the external submodule I had to first do the following (on a fresh - noncloned repo): "git remote add origin .." and then "git submodule add ../extern/LibName lib". thanks again Vic!
deepblue
sorry, Von, not Vic :)
deepblue
@deepblue: you're welcome:) And you are almost there ;) It's Von*C* , not Von. But anyway, I learn some more on this submodule topic answering your question, so you can call me whatever you want.
VonC
sure,VonC ;) thanks
deepblue