Thread (3 messages) flat view 3 messages, 3 authors, 2021-01-05

Re: How to get the branch HEAD points to using a plumbing command?

From: Jeff King <hidden>
Date: 2021-01-05 20:02:10

On Tue, Jan 05, 2021 at 04:24:56PM +0100, Ævar Arnfjörð Bjarmason wrote:
quoted
My question is, is there a "better" (more idiomatic, less
"expensive", etc.) way of doing it using only one plumbing command?
This solution is OK but it is more work than just matching one line
with a regular expression. The reason I want to do this using only
plumbing commands is because I think that plumbing command interface
would be more stable than the format (organization, structure) of
files under the `.git/` directory across Git versions. Please
correct me if I'm wrong in this idea as well.
You'll want to use git-rev-parse for this, e.g.:

    $ git rev-parse --symbolic-full-name HEAD
    refs/heads/master
Another option is:

  git symbolic-ref HEAD

which has the benefit of working even when HEAD points to an unborn
branch. It also has a --short option to drop the refs/heads/ part.

It's also worth noting what you'd see on a detached HEAD. With rev-parse
you'll see "HEAD", but symbolic-ref will exit with a non-zero code.

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help