
and zero or more pointers to the commit or commits that were the direct parents of this commit: zero parents for the first commit, one parent for a normal commit, and multiple parents for a commit that results from a merge of two or more branches. When you commit in Git, Git stores a commit object that contains a pointer to the snapshot of the content. That begs another question, then: how are commits ordered sequentially? That is, how can you tell what the other commits in a branch are, if a branch is just a pointer to one single commit? Clearly we aren’t dealing with folders here. And, think about it - you’d never have a branch stored inside of another branch. Branches being pointers implies that Git stores its data in a flat structure, rather than as a directory - which is actually true! In fact, all commits live next to each other at the same level. However, if a branch is just a “pointer” or reference to a specific commit, then that mental model doesn’t work at all. If that were the case, then it would make sense to want to create a branch as if you were creating a folder, using some kind of “create” command. This is a pretty interesting conceptual model, because if you’re anything like me, you initially imagined a branch as being more of a folder than anything else, with commits stored inside of it somehow. Every time you commit, it moves forward automatically. As you initially make commits, you’re given a master branch that points to the last commit you made. The default branch name in Git is master. Here’s what they have to say:Ī branch in Git is simply a lightweight movable pointer to. In order to understand what a branch is, let’s dive into the Git docs on branching.

In this article, we’ll dive deep on Git branches to understand why they chose to express this behavior in such a non-obvious manner. However, if you understand how git branches work below the surface, you’ll realize why this makes sense, and is ultimately the better way of describing what happens when you create a branch. This is the fastest and easiest of creating a branch from the command line, but at first glance, this command is much less intuitive or easy to remember. > testing-repo git:(main) $ git checkout -b my-branch
