On , I learnt ...
That git for-each-ref support conditional logic in its format
Git’s for-each-ref command allows you to iterate over refs and
print them according to the --format option.
The format options are different to those for git log. In particular, they
allow conditional logic using %(if)%(then)%(else)%(end) syntax.
Here’s some example usage where we print your local branches in different colours depending on whether they have an upstream tracking branch.
git branch --format='%(if)%(upstream)%(then)%(else)%(color:dim)%(end)%(refname:short)%(color:reset)'
Hat-tip to Sam Searles-Bryant for this tip.