xetra11 xetra11 - 26 days ago 6x
Git Question

What command to use to see what branch my actual branch derived from?

I'd like to see what branch my actual branch I'm on is derived from. I already took a look at the log but it's so noisy and I want to get 100% sure to find the correct branch in this case.


This problem cannot be answered in every case. Branches are not persistent: you are free to move branches around. The reflog will allow you to see some history of the branch, but the reflog is only local and will be limited to 90 days (by default).

You can use git reflog <branch> to get the first occurrence of this branch in your repo:

$ git reflog branch | tail -n 1
03302d2 branch@{12}: branch: Created from HEAD

In this example, 03302d2 is the first commit of that branch. Then, you can find the branches that the parent of this commit came from. For example, you could do

$ git branch --contains 03302d2^

See the linked question for more sophisticated ways. But note again that this search is not complete and you may miss the "correct" branch.