From: Junio C Hamano Date: Wed, 21 Sep 2016 16:37:08 GMT Subject: Re: v2.9.3 and v2.10.0: `name-ref' HEAD gives wrong branch name Message-ID: In-Reply-To: Jakub Narębski 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).