W dniu 21.09.2016 o 18:37, Junio C Hamano pisze:
> Jakub Narębski <jna...@gmail.com> 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).

I'm sorry, I was wrong saying "does not work".  The problem is not
that it does not work, but that you need to take care of exit 
condition to correctly support detached HEAD state, and not end
with empty name for a branch, for example...

But if handled correctly, git-symbolic-ref is as good as git-rev-parse
as a plumbing to resolve current branch name.

Jakub Narębski

Reply via email to