QuocNg
QuocNg

Reputation: 152

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

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?

Upvotes: 3

Views: 1889

Answers (2)

VonC
VonC

Reputation: 1324178

Is there any way we can drop the quote?
I'm trying to make an alias for this on linux shell, e.g. alias gis='git submodule foreach git'

You would need a git alias with parameters:

alias git = '!f() { git submodule foreach "git switch ${1} || :"; }'

I am using here git switch (Git 2.23, Q3 2019) instead of git checkout. git switch works only with branches, not "branches or files" like git checkout.

Upvotes: 0

phd
phd

Reputation: 94473

Ignore all errors with this shell syntax:

git submodule foreach "git checkout featureABC || :"

: means "do nothing".

Upvotes: 5

Related Questions