0

I run

.../$ git branch -a
  master
  temp
* version_1
  remotes/origin/master
  remotes/origin/temp
  remotes/origin/version_1

but then:

.../$ v="$(git branch -a)"
.../$ echo $v
master temp bent bent.sh core LICENSE notes old README.md res version_1 remotes/origin/master remotes/origin/temp remotes/origin/version_1

I get that storing a variable this way removes the new lines (& need to look up how to fix that).

But why, oh why, is it adding my files (bent bent.sh core LICENSE notes old README.md res) and how can I stop it?

I'm trying to get an array of branch names, so I can make a prompt to choose branch name via a number

Reed
  • 14,703
  • 8
  • 66
  • 110
  • Same thing happens with `git branch -l`, but not `git branch -r` – Reed Aug 29 '20 at 16:07
  • 1
    the newlines are there. Add quotes in the `echo` command. The files are from the `*` which is expanded in the echo command. – Marco Aug 29 '20 at 16:11
  • Ohhhh! Because it's executing `echo *` on that line, basically? Makes sense. That did it! I think I've known that before... lol – Reed Aug 29 '20 at 16:13
  • Other useful links: https://stackoverflow.com/questions/3846380/how-to-iterate-through-all-git-branches-using-bash-script and https://stackoverflow.com/questions/26724818/for-loop-over-all-git-branches-with-certain-name – Reed Aug 29 '20 at 16:31

0 Answers0