Maybe it might be a strange need, but I believe it would be helpful to have something like this:
if($branch$ === \"master) { // Special code for the maste
If you need that information in hooks, the usual way is to not rely on a porcelain command, but on plumbing ones:
#!/bin/sh branch=$(git rev-parse --symbolic --abbrev-ref HEAD)