2

I first did repo sync to a manifest for a branch name myBranch. I then get the tags from

git tag -l

Now I want to know using git that each tag obtained as a result of git tag -l was actually created on which branch. Please note : I do not want myBranch as the output but the remote branch name on which the tag was created.

CharlesB
  • 75,315
  • 26
  • 174
  • 199
iDev
  • 1,717
  • 5
  • 31
  • 52
  • 1
    Does this answer your question? [How to get the branch from tag name in Git?](https://stackoverflow.com/questions/12754078/how-to-get-the-branch-from-tag-name-in-git) – ttfreeman Nov 04 '19 at 13:30

3 Answers3

4

Keeping aside the fact that branches can be renamed or deleted at any time (without losing any commits, which can still be referenced in the path of another branch), the best you can do is:

  • get the branches that contains the commit referenced by the tag

See "Show the original branch for a commit", combined with "Git - how to tell which commit a tag points to".
(Ie, a combination of git rev-parse <tag>~0 with git branch --contains <sha1>)

This has nothing to do with the branch on which the tag was created, but rather the branch(es) which currently reference said tag.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
2

No such thing. Tags point to commits, and branches point to commits. A single commit can be pointed at (or be a parent of) dozens of different branches; there is no way to narrow down one specific branch as "the owner of this tag". The branch might have been deleted from upstream before you fetched it, and only the commit remains, as another example of why this can't work.

amalloy
  • 75,856
  • 7
  • 133
  • 187
0

Try this:

branch=$(git for-each-ref | grep ${commit_num} | grep origin | sed "s/.*\///")
ttfreeman
  • 3,082
  • 2
  • 20
  • 28