Why does switch of branch update submodule (without explicit pull)?

I just cloned a repository, I never worked on before. It contains submodules, so I did

~/projects/myProject (master) $ git submodule init
~/projects/myProject (master) $ git submodule update

Since I needed a newer version of the submodule, I tried to update via:

  • How to share my project via GIT if I have git server in internet?
  • How to merge a specific commit in Git
  • Git “git config --global user.name” why does this option exist?
  • Merge some commits in pull requests in Github
  • Specify explicit fetch ref when doing “git svn init”
  • Separate Git Deployments on a Single Server
  • ~/projects/myProject (master) $ cd subs/mySubmodule
    ~/projects/myProject/subs/mySubmodule ((no branch)) $ git checkout master
    ~/projects/myProject/subs/mySubmodule (master) $ git pull
    

    And got

    Already up-to-date.
    

    WTF?

    After investigating the situation with removing everything and retry the whole thing, I realized that the submodule was actually updated with the branch switch and by that the pull was not necessary and the response (Already up-to-date.) was correct.

    So why is that?

  • Pushing to bitbucket with libgit2sharp
  • git - Is it possible to exclude file from `git push`, but keep them in the local repository?
  • How to fix case sensitivity in Windows Git repository
  • git log history simplification
  • git2p4 submit fails because of illegal characters in filenames
  • How to clear git caches?
  • One Solution collect form web for “Why does switch of branch update submodule (without explicit pull)?”

    It’s not quite right to say that the switch updated the submodule. The submodule was updated when you ran git submodule update. Submodules are a bit weird. As this page says:

    git submodule update to fetch all the data from that project and check
    out the appropriate commit listed in your superproject:

    So, if you run git submodule udpate, you already have all the changes from the repo, even if the version you’re seeing isn’t the latest. This is because each branch has a specific commit associated with it. The code you see might be old, but the submodule will already have all the latest data. Then, when you git checkout master you’re switching to the latest version available, and git pull doesn’t do anything.

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