As someone relatively new to Git, I have recently (and finally!) understood that a branch is actually just a pointer to a particular commit, and that sometimes it might be better to rephrase "which branch a commit belongs to" as "from which branches is a commit reachable".
For example, the following diagram is from the official Git documentation:
In this image, I would intuitively think that commit C4 "belongs" to the branch master and commits C3 and C5 belong to iss53. But what about C0 through C2? Would they belong to both branches? Or must I say they are "reachable" by branches master and iss53?
This gets more complicated once I merge iss53 into master:
Since branch iss53 was merged into master, does that make commits C0 through C2 belong to master "more" than iss53?
What if I delete branch iss53 after the merge? Which branch would commits C3 and C5 belong to? After thinking about it more, it seems that after the merge, commits C4, C3, and C5 are "equal" in terms of the branching history and I can't tell which branch the three of them belong to. This is because after deleting iss53, there doesn't seem to be any information as to whether C4 belonged to any historical branch any more than C3 and C5.
I have found this answer which says that it is better to think about this in terms of "from which branches can this commit be reached". But does that mean C4, C3, and C5 are all reachable from the master branch??? But how do you handle the branching parentage that happens in the diagram? Does that matter?
Also, the answer I linked to stated that there could cases where a commit cannot be reached by any branch, how can that happen? And what are its implications?
But my main question remains: How do I associate commits with branches?
P.S. A side/off-topic question that stems from this post would be: Can a commit have more than two parents?


 
     
    