3

I am trying to update my submodules so that they use a more recent commit.

When we use submodules, they are supposed to remain in a detached head state. That's fine.

$ cd myproject
$ cd otherlibrary
$ git status .
HEAD detached from 091eccc
nothing to commit, working tree clean

I did some work in otherlibrary and now I'd like to update myproject so that it will use these new commits in otherlibrary. That means, I need to 'update the submodule' somehow.

This doesn't work: (see? it's still has the same commit number)

$ cd myproject
$ cd otherlibrary
$ git submodule update --remote
$ git status .
HEAD detached from 091eccc
nothing to commit, working tree clean

For completeness, I also tried it like this git submodule update --rebase --remote and like this git submodule update --merge --remote and that doesn't make any difference.

I also read these two SO articles that talk about the subject, but my problem isn't solved by this:

101010
  • 14,866
  • 30
  • 95
  • 172
  • In what way `git submodule update --remote` doesn't help? – phd Jan 12 '20 at 15:53
  • Well, ignoring every other fact and only caring about the end result, the result is that whatever is now in the `otherlibrary` folder after that command, is still not the most recent code. – 101010 Jan 12 '20 at 16:47
  • 1
    `git submodule update --remote` must be run from the superproject: `cd myproject` but not `cd otherlibrary` – phd Jan 12 '20 at 18:01
  • Ok that works. But how do I update just `otherlibrary` in a situation where I have 10 submodules? – 101010 Jan 13 '20 at 02:12
  • `git submodule update --remote otherlibrary && git add otherlibrary && git commit -m "Update otherlibrary"`. Or `cd otherlibrary && git checkout master && git pull && cd .. && git add otherlibrary && git commit -m "Update otherlibrary"` – phd Jan 13 '20 at 08:49

1 Answers1

3

As phd noted in a comment, to use git submodule update, you must be in the superproject.

(All git submodule update --remote does is cd into the submodule, run a git fetch, and then run a git checkout, so if you don't want to pop back up to the superproject for some reason, you can run the git fetch and git checkout yourself. If you do this, you can poke around in the fetch results and carefully choose the specific commit you'd like, rather than just taking the one identified by origin/master or whatever. Of course, if the one you'd like is whichever one is identified by origin/master, the git submodule update --remote is convenient.)

torek
  • 448,244
  • 59
  • 642
  • 775
  • What if I have 10 `otherprojects` and I don't want them all updated? – 101010 Jan 13 '20 at 02:07
  • In that case, you can either limit the `git submodule` command to one specific submodule, or—my preferred method—just `cd` into the submodule yourself and work there until satisfied. – torek Jan 13 '20 at 05:22