5

I have a git repository with 2 branches:

$ git branch
* master
  test/branch

I can list specific branches individually by doing the following:

$ git branch --list master
* master

$ git branch --list test/branch
  test/branch

However, when I store this command as a variable, I get unexpected results:

$ LOCAL=$(git branch --list master); echo $LOCAL
index.php readme.md master

$ LOCAL=$(git branch --list test/branch); echo $LOCAL
test/branch

The results aren't always consistent. Sometimes I get unexpected results from branches with forward slashes, sometimes without, depending on the repository I'm working with. I can't put my finger on what's happening exactly or why.

Why does listing one branch list files in the directory and the branch itself, and the other one just lists the branch?

1 Answers1

5

Above, it looks like Bash is expanding the * which appears at the start of $LOCAL. Try echo "$LOCAL".

  • @AuditeMarlow If this answer solved your issue, please take a moment and accept it by clicking on the check mark to the left. That will mark the question as answered and is the way thanks are expressed on the Stack Exchange sites. – terdon Sep 23 '16 at 15:22