From: "Jakub Narębski" <jnareb@gmail.com>
To: Kevin Daudt <me@ikke.info>, ryenus <ryenus@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Notation for current branch?
Date: Sun, 28 Aug 2016 15:56:05 +0200 [thread overview]
Message-ID: <4114ccbc-6b23-b7fe-ce4a-fcd0c9e4038a@gmail.com> (raw)
In-Reply-To: <20160828105159.GA5477@ikke.info>
W dniu 28.08.2016 o 12:51, Kevin Daudt pisze:
> On Sun, Aug 28, 2016 at 05:58:18PM +0800, ryenus wrote:
>> I wonder if there's an easy to use notation to refer to the current branch?
>> which is expected be friendly to scripting.
>>
>> For HEAD, there's @, which is short and concise.
What's wrong with simply using 'HEAD' for scripting?
>>
>> But for the current branch, it seems one has to either use a not so friendly
>> plumbing command, or grep/parse the output of `git branch`, since the latter
>> doesn't even has any option to only print the plain name of the current branch,
>> or maybe an option can be added to `git branch`?
>
> Scripts should always rely on plubming commands, never on porcelain, as
> their output will change, and thus, break scripts.
It is not something theoretical; the output of "git branch" for detached HEAD
(aka anonymous / unnamed branch) did change.
> To get the current branch name, the best is to use `git rev-parse
> --symbolic-full-name`[1], which either returns you the current branch name
> (eg refs/heads/master), or HEAD, when you have a detached HEAD. If you
> only want the friendly name, add --abbrev-ref, which would then return
> master.
>
> [1]: git symbolic-ref HEAD would also work, but errors out when you're
> not on a branch.
Note that in some cases current branch is implied, like e.g. in
"@{<n>}" notation.
--
Jakub Narębski
next prev parent reply other threads:[~2016-08-28 14:00 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-28 9:58 Notation for current branch? ryenus
2016-08-28 10:51 ` Kevin Daudt
2016-08-28 13:56 ` Jakub Narębski [this message]
2016-08-29 6:39 ` Jacob Keller
2016-08-29 19:49 ` Junio C Hamano
2016-08-29 19:52 ` Jacob Keller
2016-09-01 15:51 ` ryenus
2016-08-30 18:09 ` ryenus
2016-08-30 18:19 ` 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=4114ccbc-6b23-b7fe-ce4a-fcd0c9e4038a@gmail.com \
--to=jnareb@gmail.com \
--cc=git@vger.kernel.org \
--cc=me@ikke.info \
--cc=ryenus@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).