I would like to include a command to delete a local Git branch in a script, and I don't want any error message to be shown if the branch does not exist. At the same time, I also don't want a status code indicating a failure from the Git command.
Given the following example:
git branch -D foo
If the branch exists, it is deleted, and the return status of the command is 0, indicating success. If I run the same script again, the branch is no longer there, therefore the command fails, prints
error: branch 'foo' not found.
and the return status of the Git command is >0, indicating an error.
Is there a way to silence the command, so that it does not care whether the branch was there in the first place? Ideally, it would not print an error message and it also would not indicate a failure through a non-zero return status.
I know that I can work around these things using some scripting magic, but I would prefer a simple solution, since I have to do the same thing on Windows (.bat) and for Unix/Linux/Mac (.sh).
Did I miss an option, or am I out of luck?