Karlovsky120
Karlovsky120

Reputation: 6362

Git submodule completely refusing to cooperate

I have two repositories. BigRepo and SmallRepo.

I want to make the SmallRepo a submodule of BigRepo.

What I did?

I First cloned BigRepo.

Then I ran

git submodule add git://github.com/Karlovsky120/SmallRepo.git submodules\SmallRepo

which successfully cloned the SmallRepo into BigRepo.

Now I ran git status and got:

new file: .gitmodules
new file: submodules/SmallRepo

If I run git submodule init it fails with the message:

fatal: No url found for submodule path 'submodules/SmallRepo' in .gitmodules

(I know it's already initialized, but the url is RIGHT THERE).

I also tried committing and pushing the changes and then deleting the local repo to clone it again, but it would fail with the same message.

I know that when I pushed the changes, the submodule appeared in the web interface, but I could not click it. I don't know if that's normal behavior.

I've looked up (and followed) a bunch of tutorials, but I have no idea why this is happening. It's supposed to be super simple, yet the most basic example is failing.

What did I do wrong?

EDIT:

Contents of .gitmodules is:

[submodule "submodules\\SmallRepo"]
    path = submodules\\SmallRepo
    url = git://github.com/Karlovsky120/SmallRepo.git

Upvotes: 0

Views: 197

Answers (1)

chenrui
chenrui

Reputation: 9886

If you don't have path restriction, then the following should do the job:

$ git submodule add git://github.com/chenrui333/config-repo.git SmallRepo
$ git submodule init


$ cat .gitmodules 
[submodule "SmallRepo"]
    path = SmallRepo
    url = git://github.com/chenrui333/config-repo.git

$ ls SmallRepo/
README.md test

I just used one-level path, which I think it may be the cause.

[UPDATE]

Turns out it is the path issue, update with modified scripts:

$ git submodule add git://github.com/chenrui333/config-repo.git SmallRepo/config
$ git submodule init


$ cat .gitmodules 
[submodule "SmallRepo/config"]
    path = SmallRepo/config
    url = git://github.com/chenrui333/config-repo.git

$ ls SmallRepo/config/
README.md test

Upvotes: 1

Related Questions