Get branch name in a tag pipeline

Why is CI_COMMIT_BRANCH variable empty in a tag pipeline?

When I start a tag pipeline this variable becomes empty. I just tagged a commit in a branch and I would like to be able to know which one.

From the docs:

The commit branch name. Available in branch pipelines, including pipelines for the default branch. Not available in merge request pipelines or tag pipelines.

If you want to get the source branch for your tag, you can use the API to get the branch your commit belongs to and start from there.