Here\'s part of the contents of my .gitmodules
file:
[submodule \"src/static_management\"]
path = src/static_management
url = gi
I had the same problem but none of the solutions above helped. The entries in the .gitmodules and in .git/config were right but the command git submodules update --init --recursive
was doing nothing. I also removed the submodule directory and did run git submodules update --init --recursive
and got the submodule directory back but with exactly the same commit as before.
I found the answer on this page. The command is:git submodule update --remote
Deleting submodule dir and its contents ("external/pyfacebook" folder) if it exists before git submodule add ...
might fix problems.
I had the same problem today and figured out that because I typed git submodule init
then I had those line in my .git/config
:
[submodule]
active = .
I removed that and typed:
git submodule update --init --remote
And everything was back to normal, my submodule updated in its subdirectory as usual.
The problem for me is that the repo's previous developer had committed the submodules/thing
folder as just a regular folder, meaning when I tried to run git submodule add ...
, it would fail with: 'submodules/thing' already exists in the index
, yet trying to update the submodule would also fail because it saw that the path did not contain a submodule.
To fix, I had to delete the submodules/thing
folder, commit the deletion, then run the git submodule add
command to add it back correctly:
git submodule add --force --name thing https://github.com/person/thing.git submodules/thing
Sort of magically, but today I ran
git submodule init
followed bygit submodule sync
followed bygit submodule update
and it started pulling my submodules... Magic? Perhaps! This is truly one of the most annoying experiences with Git…
Scratch that. I actually got it working by doing git submodule update --init --recursive
. Hope this helps.
PS: Make sure you are in the root git directory, not the submodule's.
This means the submodules haven’t been set up correctly and a git submodule add
command will have to be executed.
IF SUBMODULES WERE ADDED CORRECTLY
To give some background, when a repo with submodules has been set up correctly someone has already performed a git submodule add
command, which does the following things:
Point 3 and 6 are relevant when you clone the superproject, and point 6 indicates whether a git submodule add
has been performed correctly and was committed.
You can check point 6 by seeing whether the folders in which the submodules should reside are already there and empty (Note: this does not require a .keep or .gitignore mechanism to be in place, since this is part of a Git mechanism.) After cloning the superproject you can also perform a git submodule
to see which submodules are expected.
You can then proceed by doing:
git submodule
will show the submodules present in the tree and their corresponding commit hash code, can serve as an initial check to see which submodules are expected
git submodule init
copies the submodules parameters from the repo’s .gitmodules file to your private .git/config file (point 4)
git submodule update
clones the submodules to a commit determined by the superproject and creates the submodules' .git folders under your superproject's .git/modules/ folder (points 2 and 5)
git submodule update --remote
same as update but sets the submodule to the latest commit on the branch available by the remote repo, similar as going in each submodule’s folder afterwards and do a git pull
or:
git submodule update --init --remote
which is all of the above combined.
Alternatively, when the repo is set up correctly, you can also do a git clone
with the --recursive
flag to include the submodules with the init and update performed on them automatically.
IF SUBMODULES WERE NOT ADDED CORRECTLY
But if the submodules are not committed correctly, and the submodules and their corresponding folders are not already recorded in the index, then first every submodule in the .gitmodules file needs to be individually added via git submodule add
before one can proceed.