The output of git branch contains the * character, which stands for your current branch:
$ git branch develop * master
Running only echo * in your shell will print the globe of your working directory:
compiler.sh HOSTNAME index.html
So, your original problem comes from the fact that after the extension, you actually use echo develop * master .
To avoid this swap behavior, you can simply specify a strong quote from branches during echo :
$ branches=`git branch` $ echo "$branches" develop * master
source share