Git submodule ignore error at branch checkout when that submodule does not have that branch

Viewed 329

I have 6 sub modules in a git repository, says submodule1, submodule2,... submodule6. On 4 sub modules: submodule1/2/4/5 I have a branch, says featureABC, on them.

When I run the checkout command:

$ git submodule foreach git checkout featureABC

there is an errror:

error: pathspec 'featureABC' did not match any file(s) known to git
fatal: run_command returned non-zero status for submodule3

I know that submodule3/6 do not have branch featureABC and I want to ignore them when run recursive checkout. So my question is: is there any way to ignore checkout error, leave the branch of submodule3/5 as it is and continue to other submodule checkout?

1 Answers

Ignore all errors with this shell syntax:

git submodule foreach "git checkout featureABC || :"

: means "do nothing".

Related