Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a project with a lot of submodules and I want to delete all remote branches named foo in the submodules, if it exists.

I am trying to following:

git submodule foreach git push origin :foo

This works as intended if the branch exists in all submodules, but if any of the submodules is missing the branch, the foreach stops:

Stopping at 'modules/bar'; script returned non-zero status.

How do I suppress the error?

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

From the git submodule man page:

A non-zero return from the command in any submodule causes the processing to terminate. This can be overridden by adding || : to the end of the command.

This means the following should do the job:

git submodule foreach 'git push origin :foo || :'

The || is an OR and executes the next command if the first one returns non-zero, the : returns true.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.