git submodule not pulling files in submodules
Asked Answered
P

3

55

I thought I had it all worked out with this new project and thought that git submodules are the way to to develop and deploy my application.

Set up my git repo (Drupal) and initialized it with the 7.12 tag of Drupal. Made my own branch. Then added the modules that are needed under sites/all/modules/contrib with git submodule add --branch 7.x git://path/to/drupal/module sites/all/modules/contrib/module

and then I thought, by pushing my repo to github, I would be able to simply pull it and then it would pull all the submodules into the deployment path. However, all my modules are not pulled, even if I do: git submodule foreach git pull or git submodule init followed by git submodule update

Turns out, I was wrong. Do I now need to redo everything in another way? If yes, please tell me how, if not, great, please let me know.

Peltast answered 7/4, 2012 at 11:22 Comment(0)
B
109

You forked the Drupal repo? Does it already have sub modules added in .gitmodules? If so you only needed to clone their branch and perform

git submodule init
git submodule update

You don't need to re-add their own sub modules to the repo.

Now if you want to add additional submodules you have to perform git submodule init; git submodule update every time you clone the repo. It will not automatically get the submodules.

Biotin answered 7/4, 2012 at 11:29 Comment(10)
Thanks. I went back to simplicity and just use a git fork of the drupal project. I wont change drupal core files so even merging in the changes from drupal core shouldn't harm my project.Peltast
Running "git submodule init" and "git submodule update" did the trick for me. I didn't know that git doesn't automatically pull submodules when you clone the repo.Mate
@Mate Because the submodule do not belong to main project. If you want to pull submodules, use git clone --recursive <url> instead when you clone the repo.Lindi
Consider convenience, you can make an alias command: alias gitup='git submodule init && git submodule update' .Lindi
Please consider removing your comment about submodules not being worth it, or perhaps link to a source or two. Thanks for this answer.Afield
@DanRosenstark Agreed, will remove. Submodules have dramatically changed since i wrote this. If you have the perms feel free to edit my answer and ill accept, then remove this comment.Biotin
removed "From everything I have read about submodules they are not worth it. They cause too many problems."Afield
Thanks. I executed git submodule update --remote --init and thought this will cover everything, but it does not. Had to manually execute it like in your answer.Culpa
If any body facing issue "Permission denied fatal: Could not read from remote repository." Then add your ssh key at git server.It will solve this errorGalarza
@sreemanthpulagam, I get the error. How can I add the ssh key?Culpa
T
7

If files for a submodule fail to be pulled, you could try deleting the folder for the submodule from your local repo. Then try

git submodule update

It should show you Submodule path <submodule-name>: checked out '<sha>'.

Check, and your files should now be pulled.

If that fails, delete the folder and try:

git submodule update --init --recursive

git submodule update --recursive --remote

Thready answered 23/11, 2022 at 4:11 Comment(0)
B
0

If the submodule is not being pulled make sure you have added.

For example:

git submodule add https://github.com/chaconinc/DbConnector

I had the same issue and after running the above command it worked.

Bedside answered 26/2, 2021 at 14:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.