git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Sixt <j6t@kdbg.org>
To: Anatol Rudolph <a.rudolph@2vizcon.com>
Cc: git@vger.kernel.org
Subject: Re: git branch command is incompatible with bash
Date: Mon, 27 Jul 2015 23:11:04 +0200	[thread overview]
Message-ID: <55B69E68.90306@kdbg.org> (raw)
In-Reply-To: <20150727121253.GC17338@2vizcon.com>

Am 27.07.2015 um 14:12 schrieb Anatol Rudolph:
> When using the git branch command, git uses a '*' to denote the current
> branch. Therefore, in bash this:
>
> 	$ branchName=$(git branch -q)
> 	$ echo $branchName
>
> produces a directory listing, because the '*' is interpreded by the
> shell.

Of course. You would write the last line as

   echo "$branchName"

These are shell fundamentals.

> While an (unwieldly) workaround exists:
>
> 	$ branchName=$(git symbolic-ref -q HEAD)
> 	$ branchName=${branch##refs/heads/}

If you want to do that in a script, this is not a work-around, but it is 
how you should do it. But you may want to use option --short to save the 
second line.

> it would still be nice, if there were a --current flag, that returned
> only the current branch name, omitting the star:
>
> 	$ branchName=$(git branch --current -q)
> 	$ echo $branchName
> 	master

Try

   branchName=$(git rev-parse --abbrev-ref HEAD)

-- Hannes

  reply	other threads:[~2015-07-27 21:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-27 12:12 git branch command is incompatible with bash Anatol Rudolph
2015-07-27 21:11 ` Johannes Sixt [this message]
2015-07-27 21:49   ` Junio C Hamano
2015-07-28  7:28     ` Johannes Sixt
2015-07-28 10:01       ` Jakub Narębski
2015-07-28 15:23       ` Junio C Hamano
2015-07-28 16:25         ` Jeff King
2015-07-28 17:27         ` Johannes Sixt
2015-07-29  0:23         ` Scott Schmit

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55B69E68.90306@kdbg.org \
    --to=j6t@kdbg.org \
    --cc=a.rudolph@2vizcon.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).