I’m trying to add a submodule to my git repo, and I’m 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, haven’t gotten that far; I’m just learning the submodule command).
Does
../extern/Lib1refer to a Git repository?If it does not, Git wouldn’t know how to have the Git repo URL to its
.gitmoduleAlso, try:
libnot already existing (even empty)Some good sources on submodules are:
and of course
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/configfile, like so:If you do have that section in
../DirName/NewRepo_withSubmodules/.git/configfile, you should be able to add../Extern/Lib1as a submodule using a relative path.All the above is inspired from the following section of the git submodule man page:
So if
NewRepo_withSubmodulesis 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.Git 2.13 (Q2 2017) will improve the detection of the default origin of a submodule.
See commit d1b3b81 (25 Feb 2017) by Stefan Beller (
stefanbeller).(Merged by Junio C Hamano —
gitster— in commit ae900eb, 10 Mar 2017)As now documented:
Git 2.20 (Q4 2018) improves local path support for submodules.
See commit e0a862f (16 Oct 2018) by Stefan Beller (
stefanbeller).(Merged by Junio C Hamano —
gitster— in commit 3fc8522, 06 Nov 2018)"
git submodule"(man) code trusted the data coming from the config (and the in-tree.gitmodulesfile) too much without validating, leading toNULLdereference if the user mucks with a repository (e.g. whensubmodule.<name>.urlis removed).This has been corrected with Git 2.42 (Q3 2023).
See commit fbc806a (24 May 2023) by Taylor Blau (
ttaylorr).(Merged by Junio C Hamano —
gitster— in commit 9cd234e, 20 Jun 2023)