git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Daudt <me@ikke.info>
To: ryenus <ryenus@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Notation for current branch?
Date: Sun, 28 Aug 2016 12:51:59 +0200	[thread overview]
Message-ID: <20160828105159.GA5477@ikke.info> (raw)
In-Reply-To: <CAKkAvazQxhtQauSb3MTVhzoK=xWbjMzQLBPQZUpp1n7VMUMJbQ@mail.gmail.com>

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.
> 
> 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`?
> 
> Thoughts?

Scripts should always rely on plubming commands, never on porcelain, as
their output will change, and thus, break scripts.

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.

  reply	other threads:[~2016-08-28 10:52 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 [this message]
2016-08-28 13:56   ` Jakub Narębski
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=20160828105159.GA5477@ikke.info \
    --to=me@ikke.info \
    --cc=git@vger.kernel.org \
    --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).