1

I know I can call git submodule update --init --recursive if modules were already added to the repo.

However, Is there way to add and pull submodules specified in the .gitmodules file even if they weren’t added to the current repo with git submodule add command?

torek
  • 448,244
  • 59
  • 642
  • 775
zhekaus
  • 3,126
  • 6
  • 23
  • 46
  • It's not `.submodule` file. Pleas [edit] and fix it in the title and the body of the question. – phd Feb 16 '20 at 17:23
  • 1
    Does this answer your question? [Convert .gitmodules into a parsable format for iteration using Bash](https://stackoverflow.com/questions/53896924/convert-gitmodules-into-a-parsable-format-for-iteration-using-bash) – phd Feb 16 '20 at 17:23
  • See the script in the accepted answer: the gist is `git submodule add --force`. – phd Feb 16 '20 at 17:25
  • @phd , id est the only way is to use bash scripts... I was hoping that git has some command which I can't find in docs. – zhekaus Feb 16 '20 at 18:05

2 Answers2

1

I think you've got a bad notion of the difference between "add" and "update". The submodule helper command is a housekeeping tool. The .gitmodules file is its notes on where to find things. When you first git submodule add a repo it updates its notes and then does an ordinary gitsubmodule init to load the local config and git submodule update to clone/fetch for you. You only need to add a submodule to your modules notes once, after that you init once per clone to load the tweakable settings from those notes, after that you do any tweaking (usually not needed) and update as needed.

jthill
  • 55,082
  • 5
  • 77
  • 137
0

Adding submodules is like "Adding a repo(source), in a repo(target)"

Now command is git submodule add -b <branch> <source-url> target-path

But caution, source must have some commits beforehand, because target track the commit of source git.

Happy linking...

WurmD
  • 1,231
  • 5
  • 21
  • 42