How to see which git branch the commit comes from (creating a release to production script)

I am trying to make an automatic release script that will create a tag in git on the development branch (or feature branch) that GO is looking at. The script should find out which remote branch the commit sha1 in $go_revision comes from, check it out, create a tag and move it to a master branch. All in one swoop. However if I issue git branch in the build dir in my development pipeline git says "master". Even though the pipeline is setup to fetch from a development branch.

Any ideas how to solve my branch problem OR any finished scripts that does what I want will be appreciated :)

I still need a way to find which branch the GO_REVISION sha1 is comming from if I at some later point in time want to recreate that exact build. In our setup we sometimes need to point our GO CI pipeline to an experimental branch and then it becomes a pain to check out the specific commit in the release script that should check it out, tag it and push it to a master branch holding only the release tags.

We assume that you will be doing these operations on agent & currently when agent checksout git repo we do not checkout the branch and hence you are not able to figure out which branch is the repo on.

If that is the issue we have this in our backlog & we are planning to fix this. And we will keep you posted on the bug fix.

Will this fix be enough for you to go ahead and do all the operations you mentioned? like find the repo URL, branch, revision. Tag it and push it on master? If not whatelse would you require to accomplish that?