I’m trying to see if a certain branch exists within a shell script.
However, git-branch seems to modify its output when interpolated. (I don’t know the exact phenomenon or terminology here)
For example, I’m trying to get the array of branches:
$ git branch
develop
* master
$ branches=`git branch`
$ echo $branches
develop compiler.sh HOSTNAME index.html master
$ echo `git branch`
develop compiler.sh HOSTNAME index.html master
A kind of ls-files seems to be getting in the way. How come? Is this Bash? Git? I’m confused.
The output of
git branchcontains the*character, which signifies your current branch:Running just
echo *in your shell will print a glob of your working directory:So your original problem arises because, after expansion, you’re actually running
echo develop * master.To avoid this directory-globbing behavior, you could just strong-quote
branchesduringecho: