I got this scenario:
-
I created a Git repository.
$ git init
-
Cloned an external repository in a sub directory. (using git-hg in my case)
$ git hg clone lib remote_uri
-
Added the the cloned library as submodule
$ git submodule add lib ./lib
-
Then I commited the changes
$ git commit -am “added lib”
After this procedure, if I git clone this repo and git submodule init/update the new one, I get the repo and the lib.
Anyway, If I try to push the repo to a bare one, and clone from the bare to another place, the new one crashes trying to get the lib.
I tried to git submodule init in the bare, but the command doesn’t work if you doesn’t have a working copy.
Someone got any idea what can be done?
** Update **
Here is an example without the hg.
This is a way to reproduce it.
/tmp$ git clone https://github.com/gitster/git.git
/tmp$ cd git/
/tmp/git [master]$ git clone https://github.com/gitster/git.git gitrepo
/tmp/git [master]$ git submodule add ./gitrepo
/tmp/git [master]$ git commit -am "added repo"
/tmp$ cd ..
/tmp$ git clone --bare git gitbare
/tmp$ git clone gitbare gittest
/tmp$ cd gittest/
/tmp/gittest [master]$ git submodule init
Submodule 'gitrepo' (/tmp/gitbare/gitrepo) registered for path 'gitrepo'
/tmp/gittest [master]$ git submodule update
fatal: repository '/tmp/gitbare/gitrepo' does not exist
Clone of '/tmp/gitbare/gitrepo' into submodule path 'gitrepo' failed
You seem to be expecting the impossible. Submodules are repositories in their own right, and to be able to clone them from anywhere, there has to be an accessible repository for them, just like there does for the parent repository. You’ve added a submodule with no public URL configuration. Git isn’t going to be able to magically fetch it out of the version you stuck in that original repository.
You need to update the URL for the submodule to something that’ll be accessible from wherever you want to clone it from. You should host it in the same way that you do your parent repository, whether that’s on a single machine, on a single network, or on GitHub.
And by the way, your reproduction instructions are not the same as your actual use case. In the toy case you’ve posted, all you have to do is correctly add the submodule, using the public URL:
and everything will work fine. If you host the thing that you’re trying to add as a submodule in a similar way, then the appropriate version of this command will work for you.