Search code examples
gitgit-submodules

How to pull a new submodule


Tried looking for answers on this site and others: StackOverflow - Easy way pull latest of all submodules

They all seem to want to talk about if you are controlling them, not if someone else added one, and I just want to pull the additional one into my project without having to stash or backup my changes if I need to delete the folder.

Should I delete the .gitmodules file, and/or the submodule directories that I have already pulled down with git clone --recursive? (StackOverflow - How to git clone including submodules?)

These commands do not seem to help either:

  • git submodule update --init --recursive seems like it did nothing.
  • git submodule update --recursive nothing.
  • git fetch --recurse-submodules output Fetching submodule ... several times.
  • git pull --recurse-submodules output the same thing, and then said Already up-to-date. after the fetch trial. Strange since in either case my submodules were already downloaded.
  • git clone --recursive ... Not tried yet. I feel like would overwrite any changes I have made, in the Stash or otherwise.
  • git submodule update --recursive --remote checked out a new commit SHA for one of the submodules.
  • git submodule update --recursive checked out a new commit SHA for one of the submodules. Could be the older, original commit level.
  • git submodule status gives the appropriate SHA, version, and name information for each, while still lacking the one that I want.
  • git submodule foreach git pull origin master
  • git submodule update does nothing.

I have been double-checking the library directory manually each time to make sure whether the additional submodule appeared or not.

I want to avoid performing certain actions, unless they are not destructive to my current repository state containing code changes, and solves my problem, in case it is a command I have mentioned but did not run, or anyone else has another to try.

I could try some of these with more effort, but I think I want to stop messing with them for now, and since I have not found the answer to this issue after doing some online searching, maybe the hopeful and eventual answer would help others anyway.

Am I suffering from the con mentioned here at all? Software Engineering - Git submodule vs Git clone

More links:


Solution

  • When you want to pull a specific new module, you can use the following command:

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

    If you wish to initialize all new submodules however. you can omit the path to the folder like so:

    git submodule update --init