Why is git submodule update not automatic on git checkout?

When switching branches with git checkout I would assume that most of the time you would want to update your submodules.

  • In what situation do you not want to update submodules after switching?
  • What would break if this was done automatically by git checkout?

Updated with example:

  • Going back to a previous commit in Gitkraken
  • Validate source code authenticity from git repository
  • How to add and commit removals made with “rm” instead of “git rm”?
  • Creating a git alias to append to .gitignore
  • “git clean -f” doesn't leave an empty directory
  • Git branch select in Jenkins with groovy script
    • Branch A has submodule S at 3852f1
    • Branch B has submodule S at fd72d7

    On branch A, git checkout B will result in a working copy of branch B with submodule S at 3852f1 (with a modified S). git submodule update will checkout S at fd72d7.

  • Highlighting un-commited code in vim for git
  • Accessing Teamcity git Change log in a build step
  • Deploy with git to dokku on digitalocean
  • unity can not import project correctly
  • Using git-shell and restricting developers to commit to their own projects
  • Cannot run aws.push for local repository head
  • 2 Solutions collect form web for “Why is git submodule update not automatic on git checkout?”

    I believe that the submodules not updating automatically is in line with the development goals of Git. Git is meant to work in a distributed mode and doesn’t presume that you are even able to connect to a non-local repository unless you explicitly tell it to. Git not auto-refreshing a submodule would be the expected behavior when thought of that way.

    With that being said, if you know that you always want those sub-modules to be pulled in and you know that you would never branch off of those submodules to another local repository, then it shouldn’t break anything if you automatically refreshed them after a checkout.

    git checkot --recurse-submodules will be added to git 2.13

    This is mentioned on the release notes at: https://github.com/git/git/commit/e1104a5ee539408b81566066aaa6963cb87d5cd6#diff-c24776ff22455a30fbb78e378b7df0b0R139

    On this mailing list thread, the Git dev Randall S. Becker says he also intends to add a submodule.recurse config later on to turn that on by default, which I think is likely to get merged at some point.

    Then we just have to wait for it to become the default on git 3.0! 🙂

    Git Baby is a git and github fan, let's start git clone.