Home > Software engineering >  Can't get git pull --recurse-submodules to work
Can't get git pull --recurse-submodules to work

Time:06-24

I'm trying to use submodules, but there's something I don't get. I added the submodule :

$ git submodule add ssh://[email protected]:4242/sdc-sasi/dss.git
$ git config -f .gitmodules submodule.dss.update merge
$ git submodule init
$ git submodule update
$ git push --recurse-submodules=on-demand
$ git add -A
$ git commit -m "Add submodule"
$ git push

Then, someone else adds a file to the submodule, commits and push. I can't get the update on my local repo :

$ git pull --recurse-submodules
###############################################################Récupération du sous-module dss
###############################################################Depuis ssh://git.bureautique.itm.lan:4242/sdc-sasi/dss
   3999c9c..1362f93  master     -> origin/master

But the link still points to the 3999c9c revision :

$ git submodule status
 3999c9c966f6fd058e0ecf9a2f3e947b609a7932 dss (heads/master)

What am I doing wrong ?

CodePudding user response:

You write:

Then, someone else adds a file to the submodule, commits and push.

Does "someone" do that in a clone of the submodule repository, and push to the submodule repository ? If yes, then the command to use in your superproject clone is:

git submodule update --remote 
git add dss # the path of your submodule
git commit

(see the doc git submodule update and the --remote flag).

The command git pull --recurse-submodules is the one to use if you want to update your superproject after someone changed the submodule pointer. I.e. after you do the above, your colleague can do git pull --recurse-submodules in their clone of the superproject to bring their working tree up to date (including their submodule working tree).

I highly recommend to read through the "Git Submodules" chapter of the Pro Git book.

  • Related