Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
Instead of the colon prefix, you can now use --delete. From git help push: "All listed refs are deleted from the remote repository. This is the same as prefixing all refs with a colon." – idbrii Aug 1 '14 at 13:14
up vote 3 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

Your Answer


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.