Search code examples
gitbitbucket-pipelinesgit-tag

How to get corresponding branch name after cloning git repo by specific tag?


I want the tag to be used only for the release branch in bitbucket pipeline. My idea is to find the branch name by tag or commit and then check it.

But this repository is obtained by tag in pipeline.

git clone --branch="{tag_name}" {repository_address}
git reset --hard {commit_num}

In this scenario, there is no branch.

$ git branch
* (no branch)

I've tried every way but can't get the corresponding branch name by the tag or the commit.

There are several branches via git branch -r --contains {commit_num}. And I don't know which is the specific branch that corresponds to.

I'm confused. Is my usage or idea wrong?


Solution

  • I am afraid your idea is wrong. There is no one-to-one mapping for branches and commits. Think about the initial commit of your repo: all branches contain it!

    If you want to keep developing on a release series, it is somewhat conventional to have a branch named after the major.minor version of its tags and keep it active even after higher releases have been made, e.g. to backport security fixes. This way you would simply clone the branch for the X.Y series, not the vX.Y.Z tag.

    Remember that latest releases will probably contain most of the past tags. E.g a 3.0 branch will only not contain the v2.X.Y tags that were made after the 3.0 branch forked from the 2.X.