6

I am trying to get the branch name from a given tag. I tried git describe --tag <tag-name> but this doesn't provide me any branch name. I tried using gitk to show to the tags and branch but gitk doesn't show me the tag. When I list out the tags git tag -l I see the tag name exist in the list.

I just want a simple command which can tell me the branch when tag name is provided.

Rakesh
  • 3,987
  • 10
  • 43
  • 68

3 Answers3

10

Tags and Branches in Git are only Labels pointing to specific snapshot of your files. That being said, Tags ain't linked to a branch, but to a commit.

As so, you have to check which branch contain the commit pointed by your tag, as so:

git branch --contains <tag name>
H.S.
  • 11,654
  • 2
  • 15
  • 32
Simon Boudrias
  • 42,953
  • 16
  • 99
  • 134
2

A tag is just an alias name for a commit.

That said, this should answer your question: https://stackoverflow.com/a/2707110/550177

Community
  • 1
  • 1
Felix
  • 35,354
  • 13
  • 96
  • 143
0

If you know the commit number the tag is linked to, you can find the branch from which the tag was placed from this command:

git_branch=$(git for-each-ref | grep ${commit_num} | grep origin | sed "s/.*\///")
ttfreeman
  • 5,076
  • 4
  • 26
  • 33