Jakub Narębski <jnareb@xxxxxxxxx> writes: >> Have you tried "git symbolic-ref HEAD"? >> >> $ git symbolic-ref HEAD >> refs/heads/master >> >> If you don't want the fully-qualified ref, you can add --short: >> >> $ git symbolic-ref --short HEAD >> master > > This does not work for detached HEAD, but perhaps you don't need > to worry about this. I am not sure what you mean by "does not work". Asking what ref HEAD points at to symbolic-ref will tell you it does not point at anything by exiting with non-zero status and that can be relied upon. Asking "symbolic-ref HEAD" has been the way how "git branch" and other commands find out what branch is currently checked out for almost eternity ("git symbolic-ref" appeared in Git v0.99.8).