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?

- 2,234
- 4
- 24
- 36
-
Maybe this can help - http://stackoverflow.com/questions/1057564/pretty-git-branch-graphs – Tom Ron May 08 '14 at 17:19
-
@TomRon I'm aware that I can do this with a graph, and I frequently do. However, a coworker (new to Git) recently asked if it was possible to simply be told the branch your branch came off of. – John M. May 08 '14 at 17:21
2 Answers
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)...

- 59,951
- 11
- 89
- 84
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
).

- 166,810
- 27
- 341
- 521