204

I have one repo hosted at https://github.com/aikiframework/json. On my local copy, I added a submodule using the command:

git submodule add [email protected]:jcubic/json-rpc.git json-rpc

Then I did a commit and push, and the changes appear on GitHub (I can click on it). But when I clone the repo:

git clone https://github.com/aikiframework/json.git

the submodule folder json-rpc is empty.

What am I missing here? Did I forget about something? Why is that folder empty?

2
  • 4
    if you forgot the --recursive flag in your git clone then you can do git submodule update --init Commented Apr 28, 2021 at 15:17
  • @CharlieParker it's in accepted answer first comment.
    – jcubic
    Commented Apr 28, 2021 at 16:30

1 Answer 1

351

OK I found it, needed to add --recursive when cloning the repo.

So the clone command ends up as:

git clone https://github.com/aikiframework/json.git --recursive

Note that if you forgot the --recursive flag you can do (thanks to @Amber):

git submodule update --init

Note that when submodules have other submodules you need recursive option (thanks for @cpprust):

git submodule update --init --recursive
9
  • 277
    Yep. You can also fetch submodules after the fact with git submodule update --init, if you already cloned but forgot --recursive.
    – Amber
    Commented Jul 6, 2012 at 7:56
  • 6
    Just faced the problem that there is a submodule on develop branch, but not yet on the master branch. When you clone the git repo using --recursive it will not find the submodule on the master branch, and you have to fetch it using Ambers comment "git submodule update --init" to get also the subomdule.
    – d4Rk
    Commented Jun 14, 2013 at 15:27
  • 14
    If you use git submodule update --init you will have to go to each repo and do git checkout master otherwise you'll get error You are not currently on a branch. on git pull when you try to update it to a newer version.
    – Noitidart
    Commented Nov 26, 2016 at 10:04
  • @Noitidart is there a way that doesn't do that? (after cloning the project already)
    – borgr
    Commented Feb 14, 2018 at 16:44
  • 1
    @Noitidart Thanks for the update --init hint. That does help when original clone didn't have --recursive in it and simply wanting to pull the missing submodules. Commented Aug 1, 2018 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.