While my mental model visualizes a Git branch as a stack of building blocks, in actuality a Git branch is a pointer to a single commit.
How Can a Single Commit Represent a Branch
Since each commit points back to its parent (see What’s a Git Commit Parent), if we know the most recent commit (i.e. the top most block), we can trace our way back to determine the entire stack of blocks.
Under the Hood
Each branch is a text file stored in the hidden directory
After cloning my example Git branch with blocks repo. I can look at the file that represents the
main branch with
This displays the following line (which is the commit hash for the commit at the tip of the
I can see the abbreviated version of this commit hash (
2b3a38b) at the tip (top) of our branch when I run
git log --oneline.
2b3a38b (HEAD -> main, origin/main) B