Improved version:
```bash
REMOTES=`$GIT ls-remote --heads --tags $GIT_REPO | awk '/\/'$ESCAPED_BRANCH'$/ {print $2}'`
```

`--tags` is needed to also look at tags. The extra `\/` and `$` in the awk pattern allow to not get false positives with substrings.