0

I have a local repository which contains multiple submodules. I want to keep my local repository's master branch always up-to-date with the upstream repository (The upstream repo also contains the same submodules; here "up-to-date" means my local repo is exactly like a mirror version of the upstream in terms of both parent repo and submodules). I get confused by the --recurse-submodules option in git pull.

a): git pull origin master --recurse-submodules

b): git pull origin master

I was wondering what exactly --recurse-submodules means? If I do not add this option, will the submodules in my local repo get updated?

I also found the command to update only the submodules :git submodule update (--remote). Do I also need to perform this command in addition to a) or b). By the way, Can anyone let me know the common/typical workflow as to keep a local repo with submodules up-to-date?

PS: my submodules are all initialized. I am working with github. Git version 2.11.0

Thank you!

kz28
  • 781
  • 8
  • 23
  • 1
    Possible duplicate of [Easy way to pull latest of all git submodules](https://stackoverflow.com/questions/1030169/easy-way-to-pull-latest-of-all-git-submodules) – Tim Biegeleisen Aug 24 '17 at 01:53
  • Thank you @TimBiegeleisen . What is not clear to me is if I use `git pull origin master` without option `--recurse-submodules`. Will the submodules in my local repo get updated? – kz28 Aug 24 '17 at 02:50
  • Your submodules won't get updated unless you add the `--recurse-submodules` option. Adding it will update each submodule to the latest from each of their respective origin repositories. Not adding the flag will simply update your main repository without updating the submodules. – Zachary Espiritu Aug 24 '17 at 04:51

1 Answers1

1

The three commands in your question each do slightly different things. Let's go down each one:

  • git pull origin master just pulls the latest version of your parent repo from your origin repository. It won't update revision hashes for your submodules.

  • git pull origin master --recurse-submodules will update each submodule to the latest from their origin repositories. This will show pending changes in your parent repo due to the updated revision hashes for your submodules.

    But wait: if you've specified "non-default" branches for your submodules, this may have unintended consequences, as it will update your submodules from their "origin" repositories, not the specified branch. See the last command in this list for more info.

  • You said git submodule update --remote in your question post, but I think you're actually looking for git submodule update --recursive --remote (the latter will recursively search through your working tree, as opposed to the former which will look only at the current folder you're in). That said...

    git submodule update --recursive --remote is similar to git pull --recurse-submodules, but with the benefit of respecting any "non-default" branches specified in the.gitmodules or .git/config files.

Zachary Espiritu
  • 937
  • 7
  • 23