2

My workplace recently switched to git and the powers that be set up components that are shared between projects as submodules, which causes widespread frustration among the people that are trying to figure out how to work with them.

After reading some Internet advice, I pull the project and submodules as follows:

git pull --recurse-submodules
git submodule update --recursive --remote --init --merge

However, sometimes checking the status of the submodules gives me something like:

> git status
On branch feature
Your branch is behind 'origin/feature' by 1 commit, and can be fast-forwarded.
  (use "git pull" to update your local branch)
nothing to commit, working directory clean

which is resolved if I do

git submodule foreach git pull

I am at a loss. Can you please tell me what I am doing wrong?

Thank you!

Alex O
  • 1,429
  • 2
  • 13
  • 20
  • http://stackoverflow.com/a/21195182/6194839 maybe `git submodule update --remote --merge` or `git submodule foreach git pull origin master` would work? Maybe `git submodule --help` might point you on the correct path. My first instict is you might have a command `--recursive --remote --init --merge` that isn't doing what you think it is doing. – Bryce Drew May 30 '16 at 17:37
  • can you clarify why you think you're doing something wrong? submodules are not meant to update unless you tell them to. – eis May 30 '16 at 19:48
  • @eis, I was under the impression that `git submodule update` will pull the latest from the submodules, which it apparently doesn't – Alex O May 30 '16 at 23:35

2 Answers2

2

From a comment by OP:

I was under the impression that git submodule update will pull the latest from the submodules, which it apparently doesn't

Indeed it does not. What it does is explained in for example here:

update

Update the registered submodules to match what the superproject expects by cloning missing submodules and updating the working tree of the submodules.

merge

the commit recorded in the superproject will be merged into the current branch in the submodule.

Superproject will always have a specific commit recorded about each of its submodules. An update command will use that commit and check it out - it won't actually update it to reference any new situation that project might have.

You're not doing anything wrong per se, that's the way it works. If you want to move the recorded commit to a latest one, you'll have to do it in another way. Doing it is better explained in this other thread, but in short, doing --remote instead of --merge looks like the thing you're after.

Community
  • 1
  • 1
eis
  • 51,991
  • 13
  • 150
  • 199
  • I am doing `--remote` (see question), that's what confuses me. Everything that I read, seems to imply that the commands are equivalent, but they don't behave so for me – Alex O May 31 '16 at 12:45
  • @AlexO ah, just noticed that you're using both. Did you try leaving merge out? – eis May 31 '16 at 16:52
  • Yes, it left me in "detached head" status on the submodules – Alex O May 31 '16 at 17:04
-2
git pull origin yourbranch --recursive
cd submodulebrach
git checkout submodulebrach
cd ..
git commit -m submodule
git push origin yourbranch 
Alper Şaldırak
  • 1,034
  • 8
  • 10
  • I fail to see how it answers my question, can you please explain? – Alex O May 30 '16 at 15:39
  • The question is asking how to update the local version of sub-modules cleanly. I don't understand why you want OP to push changes here. – Bryce Drew May 30 '16 at 17:37