The outcome of review on my 'Suggested Edit' to the 'Update' on initial question was 'It should have been written as a comment or an answer', so I'm posting it here:
The another way proposed will not only verify branches but any reference with such name @jhuynh.
git rev-parse --verify <reference-name>
# $? == 0 means reference with <reference-name> exists.
Issue with an 'Update' on initial quiestion explained:
Lets assume and check that 'master.000' is only a tag, such local branch does not exist, grep returns one entry wchich is a tag. Still rev-parse will return 0 if reference exists, even if such local branch does not exist. This is a false match, exactly as mentioned by @paul-s
$ git show-ref |grep master.000
f0686b8c16401be87e72f9466083d29295b86f4a refs/tags/master.000
$ git rev-parse --verify master.000
f0686b8c16401be87e72f9466083d29295b86f4a
$ echo $?
0
git branch | grep -w <branch-name>
. Ok, it's a porcelain command, but I can't imagine this particular usage to be change significantly in the future as to make this snippet unusable...git rev-parse --verify <branch_name>
verifies also other references such as tags and commit hashes, so although it might be more suitable for what you need it will return false positives if you are only interested precisely in branches.