Consider the following: a main branch and a feature branch almost ready for merging. The main branch gets updated, and the feature developer decides to merge main into their feature branch before making a pull request, to make things easier for upstream approval.
Then, the commit graph ought to look something like this, with the original branch creation in green, and the merge from main in red:
My question is: How does git remember that the feature branch, as an abstract "branch", follows the path on the bottom, and not the path through the red line? There is the git reflog, but upstream/GitHub/any-other-user doesn't get to see this.
Is this why git gives warnings for merging from main into a feature branch?
You're right that branches are just pointers to commits, but commits themselves record their parents, ordered.
So in your example, the feature
branch points to a commit with two parents, the first one being feature~
and the second one being main
. Then git knows it merged main
into feature~
and not the other way.