I'm writing a prepare-commit-msg
hook which appends the branch name to the commit msg. I m using this line to get the branch name
local current_branch=$(git rev-parse --abbrev-ref HEAD)
The problem is that if no prior commit exists (when the repo was just initizalised) the command fails with the following error message
git rev-parse --abbrev-ref HEAD
HEAD
fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.
Is there some better way to get at the branch name, or to suppress the warning / error?