Git will not init/sync/update new submodules
Here's part of the contents of my .gitmodules
file:
[submodule "src/static_management"]
path = src/static_management
url = git://github.com/eykd/django-static-management.git
[submodule "external/pyfacebook"]
path = external/pyfacebook
url = http://github.com/sciyoshi/pyfacebook.git
However, .git/config
only contains the first:
[submodule "src/static_management"]
url = git://github.com/eykd/django-static-management.git
The second submodule (external/pyfacebook
) was added by another developer in a feature branch. I've inherited the development now, and have checked out the feature branch. However, Git will not pull the submodule for me. I've tried:
git submodule init
git submodule update
git submodule update --init
git submodule sync
- Removing all submodule definitions from
.git/config
and runninggit submodule init
. It only copies over the previously existing submodule and ignores the new one. - Entering new submodule definitions in
.git/config
manually and runninggit submodule update
. Only the previously existing submodules bother to update.
in various combinations, but git simply will not update .git/config
based on the new contents of .gitmodules
, nor will it create the external/pyfacebook
folder and pull the submodule's contents.
What am I missing? Is manual intervention (adding a submodule entry by hand to .git/config
) truly required, and why?
Edit: Manual intervention does not work. Manually adding the new submodule entry to .git/config
doesn't do a thing. The new submodule is ignored.
I had this same problem - it turned out that the .gitmodules file was committed, but the actual submodule commit (i.e. the record of the submodule's commit ID) wasn't.
Adding it manually seemed to do the trick - e.g.:
git submodule add http://github.com/sciyoshi/pyfacebook.git external/pyfacebook
(Even without removing anything from .git/config or .gitmodules.)
Then commit it to record the ID properly.
Adding some further comments to this working answer: If the git submodule init or git submodule update does'nt work, then as described above git submodule add url should do the trick. One can cross check this by
git config --list
and one should get an entry of the submodule you want to pull in the result of the git config --list command. If there is an entry of your submodule in the config result, then now the usual git submodule update --init should pull your submodule. To test this step, you can manually rename the submodule and then updating the submodule.
mv yourmodulename yourmodulename-temp
git submodule update --init
To find out if you have local changes in the submodule, it can be seen via git status -u ( if you want to see changes in the submodule ) or git status --ignore-submodules ( if you dont want to see the changes in the submodule ).
git version 2.7.4. This command updates local code
git submodule update --init --force --remote
Had the same issue, when git ignored init
and update
commands, and does nothing.
HOW TO FIX
- Your submodule folder should be committed into git repo
- It shouldn't be in .gitignore
If that requirements met, it will work. Otherwise, all commands will execute without any messages and result.
If you did all that, and it still doesn't work:
- Add submodule manually, e.g.
git submodule add git@... path/to
git submodule init
git submodule update
- commit and push all files -
.gitmodules
and your module folder (note, that content of folder will not commit) - drop your local git repo
- clone a new one
- ensure that
.git/config
doesn't have any submodules yet - Now,
git submodule init
- and you will see a message that module registered -
git submodule update
- will fetch module - Now look at
.git/config
and you will find registered submodule