How to pull a new submodule

You have to do two things:

  1. Do git pull in your main repository which holds the submodules. This will add the new submodule as an empty directory.
  2. Do git submodule update --recursive --remote in the main repository. This will pull the latest changes for all submodules, including the new one.

This works at least in Git 2.13. Also note that if the repositories and submodules are on GitHub, you have to make sure you have access rights to them (if they are private).


This should work, as long as the new submodule is in the .gitmodules in remote

git pull --recurse-submodules


git submodule update --init local/path/to/submodule/folder

Best suggestion I have received so far is to run this command:

git submodule add <URL_to_submodule> <local_path_to_place_submodule>

So it looks to be what the other contributor would have done, that I would do again, even though it already exists in the remote.

I guess this doesn't technically update the .gitmodules file from the remote's data like what would be expected, but haven't found a way to do that yet.

Credit for the help goes to @pandatrax.

Update

Before trying the add method, I tried 1 more idea that involved copying the .gitmodules file from the remote manually and trying any of the update commands, but sadly that approach did not work either. It may have gone differently if I executed the commands in the root, since I was in a subfolder, but I doubt it.

Then I used the add method, which downloaded the dependency, but the .gitmodules file showed changes. Once I set-up the GitHub remote and pulled from it after discarding that file, the project seems to be in a better state now, even syncing the commit SHAs for the updated module or 2, either since they matched, or it was overwritten.