Git: How to find out on which branch tag is?

I’m currently busy with project with a lot of branches and I have a tag for last changes which where done on one of the branches. But it’s not clear for me on which branch this tag.

How to find out on which branch tag is?

  • Bitwise operators, not vs xor use in branching
  • Get git branch name in Jenkins Jenkinsfile
  • How do I see the commit differences between branches in git?
  • Should a “Release Candidate” be immutable?
  • How to choose the right branch/fork to use by looking on the github's network graph?
  • SVN: Best way to share common code across projects
  • Git (TortoiseGit) - How to revert a single file to a previous revision and then undo the revert?
  • git pull -v: up to date but isn't
  • How to push my code to github fork
  • Do git tags get pushed as well?
  • Confusing error from | xargs sed
  • Why does my refs/remotes/origin not have a ref to master?
  • 5 Solutions collect form web for “Git: How to find out on which branch tag is?”

    Even shorter:

    git branch --contains tags/<tag>
    

    (it works for any tree-ish reference)


    If you can find which commit a tag refers to:

     git rev-parse --verify tags/<tag>^{commit}
     # or, shorter:
     git rev-parse tags/<tag>~0
    

    Then you can find which branch contain that commit.

    git branch --contains <commit>
    

    As commented below by user3356885, for the fetched branches (branches in remotes namespace)

    git branch -a --contains tags/<tag>
    git branch -a --contains <commit>
    

    If “git branch –contains ” does nothing, be sure that you are including all branches, both remote and local branches:

    git branch -a --contains <tag>
    

    From the git help:

    Specific git-branch actions:
    -a, –all list both remote-tracking and local branches

    With a Tag you mark a reference. So when you are on a dev branch and Tag this state. Your tag is on the actual reference. So in this case you can look to gitk or another tool where the tree is shown. There you can see on which reference the Tag is.

    git: Is there something like per-branch tags?
    http://git-scm.com/book/en/Git-Basics-Tagging

    Here is a good explanation.

    git branch --contains tag
    

    does nothing for me, but I found my solution to this problem in git gui.

    Start it like this:

    git gui
    

    (On my Ubuntu I had to install it first with sudo apt-get install git-gui.)

    Then I selected the menu item Repository -> Visualize All Branch History. In the resulting window I then selected the menu item File -> List References.

    Another window popped up, listing all my tags (and other references). These are clickable and after clicking one of them I just had to check the bottom left frame for the list of branches. Like this:

    Parent: somesha (message)
    Parent: someothersha (another message)
    Child:  anothersha (yet another message)
    Branches: branch1, master, remotes/origin/branch2, remotes/upstream/branch1, etc
    Follows: v1.1.2
    Precedes: v1.1.4
    

    In regards to @VonC’s comment about finding the commit referenced by a tag, just use:

    git show <tag>
    

    Since a tag is tied to a specific commit, it can be used to show that commit – which will give you the full commit details.

    Git Baby is a git and github fan, let's start git clone.