git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git branch in Bash subshell "$(git branch -a)" including ls output as part of return?

From
Charles Bailey <charles@hashpling.org>
Date
Dec 7, 2015, 16:58 UTC
Message-ID
<20151207165810.GA25856@hashpling.org>
In-Reply-To
<CAJGk2Wx4B=AHFxkJep=yYVKU9UyJieazoNaC44W5yBXoMi+gdg@mail.gmail.com>
On Mon, Dec 07, 2015 at 11:52:28AM -0500, Alex Jones wrote:
Show 28 quoted lines
> git branch -a output:
> 
> ajonespro:Deploy_Script ajones$ git branch -a
> 
> * DWH_concurrent_api
>   Email_No_Error_If_No_Old_Version
>   IT/configs_in_app_support
>   PHP_Build_Repo
>   master
>   remotes/origin/DWH_concurrent_api
>   remotes/origin/Email_No_Error_If_No_Old_Version
>   remotes/origin/IT/configs_in_app_support
>   remotes/origin/PHP_Build_Repo
>   remotes/origin/master
> 
> echo $(git branch -a) output:
> 
> ajonespro:Deploy_Script ajones$ echo $(git branch -a)
> AppDeploy WebDeploy DWH_concurrent_api
> Email_No_Error_If_No_Old_Version IT/configs_in_app_support
> PHP_Build_Repo master remotes/origin/DWH_concurrent_api
> remotes/origin/Email_No_Error_If_No_Old_Version
> remotes/origin/IT/configs_in_app_support remotes/origin/PHP_Build_Repo
> remotes/origin/master
> 
> While it might be hard to see from that output, The first two
> "branches" in the subshell's output are actually the directories
> contained within the repo.

Looking at the two outputs, you are seeing the shell's glob expansion of the '*' current branch marker. You probably want to quote the command expansion to prevent this:

echo "$(git branch -a)"
Previous: Alex JonesNext: Charles Bailey
Message 2 of 4 in “git branch in Bash subshell "$(git branch -a)" including ls output as part of return?”
  1. Alex JonesDec 7, 2015
  2. Charles BaileyDec 7, 2015
  3. Charles BaileyDec 7, 2015
  4. Alex JonesDec 7, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.