From: Jeff King <peff@peff.net>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Utku <ugultopu@gmail.com>, git@vger.kernel.org
Subject: Re: How to get the branch HEAD points to using a plumbing command?
Date: Tue, 5 Jan 2021 15:01:11 -0500 [thread overview]
Message-ID: <X/TFh+SLYqbT1lT9@coredump.intra.peff.net> (raw)
In-Reply-To: <8735zfs8xj.fsf@evledraar.gmail.com>
On Tue, Jan 05, 2021 at 04:24:56PM +0100, Ævar Arnfjörð Bjarmason wrote:
> > 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
next prev parent reply other threads:[~2021-01-05 20:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-05 15:09 How to get the branch HEAD points to using a plumbing command? Utku
2021-01-05 15:24 ` Ævar Arnfjörð Bjarmason
2021-01-05 20:01 ` Jeff King [this message]
2021-01-05 22:55 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=X/TFh+SLYqbT1lT9@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=ugultopu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).