Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 656
diveintohacking Avatar asked Feb 19 '13 15:02

diveintohacking


2 Answers

Just add || true to your submodule command:

git submodule foreach 'git commit -m "my commit message" || true'
like image 178
Shprink Avatar answered Nov 14 '22 23:11

Shprink


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.

like image 42
twalberg Avatar answered Nov 15 '22 01:11

twalberg