recursively git pull for all of the git submodules simply

My personal repository has some repositories as submodules. And the following command

$ git submodule foreach git pull origin master

was faced with the following result right after entering ruby repository because ruby repository seems that it does not have a master branch and “git pull” stopped.

Entering 'rails'
From git://github.com/rails/rails
 * branch            master     -> FETCH_HEAD
Already up-to-date.
Entering 'roo'
From git://github.com/hmcgowan/roo
 * branch            master     -> FETCH_HEAD
Already up-to-date.
Entering 'ruby'
fatal: Couldn't find remote ref master
Stopping at 'ruby'; script returned non-zero status.

So my question is what should I do to git pull for all of submodules only by git command? Should I do make a script to this? I hope just ONE command line provided from git will make this.

  • Remove git submodule/repo inside repo fatal: Pathspec 'xfile.md' is in submodule 'x'
  • Recommended workflow for multiple modules (themes)
  • Can I put a .gitmodules file in a subdirectory?
  • switching a subdirectory managed by git to a submodule
  • Git fetch submodules from latest gitmodule
  • Git repo not updating github.io content
  • Is there a way to include a particular version of a git submodule in a project tag?
  • How to know if a git submodule commit is already pushed into the repository
  • 2 Solutions collect form web for “recursively git pull for all of the git submodules simply”

    git submodules are typically in detached-HEAD states, and thus git pull on them can’t figure out what you mean when it comes to the merge phase. If all you are trying to do is get the latest changes into the repository, try git submodule foreach git fetch instead. If you want to get each submodules master updated to its respective origin/master, then you can follow up with git submodule foreach git checkout master; git submodule foreach git merge origin/master.

    Then, of course, you need to decide what version of each submodule you want your main repository to use (I would not recommend blindly going with origin/master all the time – it may be unstable – better to pick a known-good tag or something), check out those versions in the submodules, and follow up with the appropriate git adds and git commit in your main repository.

    Just add || true to your submodule command:

    git submodule foreach 'git commit -m "my commit message" || true'
    
    Git Baby is a git and github fan, let's start git clone.