Skip to Content
Navigation:

A stick figure smiling

Here's a preview from my zine, How Git Works! If you want to see more comics like this, sign up for my saturday comics newsletter or browse more comics!

Image of a comic. To read the full HTML alt text, click "read the transcript".

browse more comics! get the zine!
read the transcript!

You can think about a Git branch in 3 different ways:

1. just the commits that “branch” off

this is how I usually think about branches:

armadillo branches off main

Illustration of a vertical black line, labelled “main”. Coming of off it is a red line, labelled “armadillo” The armadillo line has two dots on it.

The two dots are labelled “I think of the armadillo branch as these 2 commits”

How this shows up in git:

Git DOESN’T KNOW that armadillo is branched off of main: for all it knows, main could be branched off of armadillo! You need to tell it when you merge or rebase, for example:

git checkout main
git merge armadillo

2. every previous commit

Even though git doesn’t treat the main branch in any special way, I think of main differently from other branches.

Illustration of a vertical red line, labelled “main”, which has four dots along it. Coming of off it is a black line, labelled “armadillo”. The red dots on the red line are labelled “I think of my main branch as these 4 commits”

How this shows up in git:

It’s what git log BRANCHNAME shows you! How git log main works:

Illustration of a vertical line with four dots along it. The dot at the top is labelled main (start here). The lines between the dots are labelled “parent”.

3. just the commit at the end

This is how branches are actually implemented in git.

Illustration of a vertical black line, labelled “main”, which has four dots along it. Coming of off it is a red line, labelled “armadillo”. The final dot along “armadillo” is labelled “the latest commit on the branch”

How this shows up in git:

It’s how branches are stored internally: a branch is fundamentally a name for a commit ID.

.git/refs/heads/main (branch name)
a276f62 (ID of the latest commit on the branch)

Saturday Morning Comics!

Want another comic like this in your email every Saturday? Sign up here!

I'll send you one of my favourite comics from my archives every Saturday.
© Julia Evans 2024 | All rights reserved (see the FAQ for notes about licensing)