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

git tag
git checkout tag
git show branch tags
git show tags
git branch
git get latest tag
git show-branch tree
git switch to tag

I'm currently busy with a 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 is.

How to find out on which branch a 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>

git-show-branch Documentation, A glob pattern that matches branch or tag names under refs/. Instead of showing the commit list, determine possible merge bases for the specified commits. However, I don't know which branch it is based on. Is there a command or a way to find out which branch my current branch originates from? I tried looking in SourceTree and also with git log --graph --all but somehow I can't really figure out the originating point when the branch was created. Thanks!

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

Tagging, A lightweight tag is very much like a branch that doesn't change — it's just a You can see the tag data along with the commit that was tagged by using the git� I create a tag on the release branch. Afterwards I'll go back to the master branch and start over with my workflow. I recently discovered a package that automatically sets the upcoming version of my package based on the latest tag. Internally it uses. git describe --dirty --tags --long --match *.* to find the previous tag.

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

How to get Branch Name from Tag, From git man: --contains [<commit>]. Only list branches which contain the specified commit (HEAD if not specified). Implies --list . and. Tags are ref's that point to specific points in Git history. Tagging is generally used to capture a point in history that is used for a marked version release (i.e. v1.0.1). A tag is like a branch that doesn’t change. Unlike branches, tags, after being created, have no further history of commits. For more info on branches visit the git branch

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.

How To Checkout Git Tags – devconnected, You can inspect the state of your branch by using the “git log” command. Make sure that the HEAD pointer (the latest commit) is pointing to your annotated tag. To delete a branch, you can use git branch -d branchname. This will only work if you have merged the changes in somewhere else (e.g. master or develop), so again, you don’t lose any work. If you want to delete it anyway, you can use git branch -D (upper case D) instead.

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.

How To List Git Tags – devconnected, In order to find the latest Git tag available on your the latest commit of your current checked out branch. I couldn't figure out how to find which branch the current dependency belongs to using only go tools. But there is a way to find which branch the commit is on using git. git clone <repo-url> && cd <repo> && git branch -a --contains <commit> Reference: Finding what branch a Git commit came from

git tag, For more info on branches visit the git branch page. -rc which returns a list of all tags marked with a -rc prefix, traditionally used to identify release candidates. $ git checkout v2.0.0 Note: checking out 'v2.0.0'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout.

Fixing GIT Branch and Tag Name Collisions, Confusion can be had when assuming a branch is always the HEAD, You can find the common parent in git using merge-base to do a Tag� Because the original commit from which a branch was started is not explicitly identified, that commit (or its equivalent) can be found algorithmically using the name of the original branch from which the new branch forked: git merge-base original-branch new-branch

Condition to check tag name and branch the tag was created from , Git does not maintain a history that corresponds tags and branches. Although a tag and a branch could be pointing to the same commit, there's no� git describe --tags --exact-match <commit-id> This gives you the tag that is ONLY for that commit and for ones without annotation. Useful when you want to find tags and not worry about stripping the formatting off then (for Jenkins for example). eg. $ git describe --tags --exact-match head~2. Gives you: $ ReleaseBeta

Comments
  • On my version of Git, 1.7.1, I can simply do git branch --contains <tag>.
  • @DanMoulding true, I have edited the answer to reflect that. I was initially interested on finding the commit attached to a tag.
  • Looking for tag that was created on remote branch won't produce any results in this case. Another words, no results will be produced for branches that do not exist locally. Option -a should be used for that. git branch -a --contains <tag>. Same will work for commits.
  • Unfortunately this returns multiple things: * (HEAD detached at 82dd3f0) master refs/tags/0.0.1-test-masterBr --> I want to programatically access the branch, no HEAD info or the tag itself
  • @herm In that case, try git branch --no-merge tags/<a-tag>