You can also try this , had similar use case and this worked for me
git ls-remote --heads origin | grep $CI_COMMIT_SHORT_SHA | sed "s/.*///"
git ls-remote --heads origin | grep $CI_COMMIT_SHORT_SHA | sed "s/.*\///" Slightly different but taking inspiration from @ttfreeman's answer