Tried above answers but there is always 'detached HEAD' issue that comes with several commands. This ones works for me so far. It will correctly output the branch name even if the branch name contains /
in the name
git describe --all --exact-match | sed 's/heads\///'