Question

Let's say you are on master, and do git checkout -B bugfix/user-profiles-nonexistent. Is there any way to now find out that you branched off of master, or does Git not track that?

Was it helpful?

Solution

As an example, consider this commit/branch graph:

A--B--C--D-------------E--P
       \                \
        \   G--H--I---M--N--O
         \ /         /
          F         /
           \       /
            J--K--L

What branch was branch O created off from? One of the branches containing F was created off the A-B-C branch, but was it the one containing G or the one containing J? Perhaps F is still a distinct branch, and both G and J were branches created from F. Furthermore, the two branches containing G and J, are later merged together again at M. There are several other ambiguous "where did this branch come from" situations there, as well. Keep in mind that the flatness of the A-B-C-D-E-P line is not significant - the graph could be redrawn with the same topology, but with A-B-C-F-J-K-L-M-N-O as the straight line; this would lead to a different set of "where did it come from" questions.

In general the question you are asking is not answerable, outside of conventions based on naming strategies, or including additional information in commit messages, or something... Some would probably argue that any answer to that question isn't even really useful or interesting (I'm not sure I would personally go quite that far, myself, though)...

OTHER TIPS

Technically, a branch is not created from another branch, it's created from a commit, so I'm not sure if the information you want is recorded. It doesn't appear to be in the reflog.

If the branch has an upstream set you can obtain it using:

git rev-parse --symbolic-full-name @{u}

but that upstream isn't always the one it was branched off, because the upstream branch can be set either when you create the branch (with --track, or automatically if branch.autosetupmerge is true) or you can set/change it later (with --set-upstream-to).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top