Chirag Patel
Chirag Patel

Reputation: 31

how to find which github branch tag is created from?

I am trying to find out which branch tag was created from? I have clone tag and ran following command but it return two branches. Tag can be generate from one branch I do not know why it return two branches.

Following command i have executed

it return two branches. I created tag from why it return two branches? remotes/origin/dev-genericrequest remotes/origin/release-dev

Upvotes: 1

Views: 848

Answers (2)

Icyvapor
Icyvapor

Reputation: 63

git branch -a --contains v1.0.0.0.1

This command is querying all git branches containing the existing tag v1.0.0.0.1. It returns two branches because both of them contain the commit this tag points to.

From the official 'git branch' doc:

With --contains, shows only the branches that contain the named commit (in other words, the branches whose tip commits are descendants of the named commit),

Upvotes: 0

daveruinseverything
daveruinseverything

Reputation: 5187

A tag is simply a reference to a commit, it has no relation to a branch. A commit may be part of the history of many branches, or none at all.

Consider:

  • I start with an empty repo. I create hello_world.txt and commit it, which becomes the first commit to the master branch.
  • I modify hello_world.txt file and add some text. I make another commit for that change on master
  • I tag that most recent commit with the tag hi
  • I create a new branch from this current state called development. At this point, both the development and master branches contain the same commit history
  • I continue to make new commits to master and development, but the tag I added will show up for both branches, as well as any new branches that are made from a commit at or after the tagged one.

I'm sure that if you check out each branch, you'll find that the commit referenced by your tag exists in the histories of both. If you visualise it like a tree branch, the tag must have existed before the "split" between the two branches occurred.

Upvotes: 3

Related Questions