Part IV: Chapter 4.1

What is a Branch?

A 41-byte file. That's it.

People think of branches as parallel universes — deep, expensive copies of the entire project. In Git, a branch is a plain text file inside .git/refs/heads/ containing exactly one thing: a 40-character commit hash and a newline. 41 bytes. Moving a branch pointer is nearly instantaneous because Git is only overwriting a tiny file.

Open a Branch File

Click a branch file in the explorer below to see its raw contents.

File Explorer

.git/
refs/
heads/

← click a file to open it

File Contents

No file selected.

A Pointer, Not a Copy

A branch does not store code. It does not store a diff. It stores a single commit hash — a pointer to one node in the commit graph. When Git needs to know "what does the mainbranch look like right now?" it opens that file, reads the hash, and follows the pointer to the commit object.

Because all the history, all the file contents, all the tree objects — they already exist in .git/objects/. The branch just says which commit to start from.

Why This Matters

In older version control systems (SVN, CVS), creating a branch meant duplicating the entire project directory on the server. It was slow and expensive, so developers avoided it.

In Git, creating a branch writes 41 bytes to disk. It takes the same amount of time whether your project has 5 files or 500,000. This is why Git encourages you to branch aggressively — it is essentially free.

Proving It with Plumbing

You don't have to take Git's word for it. You can read the branch file directly.

Terminal
$cat .git/refs/heads/main
c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3
$wc -c .git/refs/heads/main
41 .git/refs/heads/main
$# That hash is just a commit object:
$git cat-file -t c4d5e6f
commit
$git cat-file -p c4d5e6f
tree f1e2d3...
parent a1b2c3...
author Badu <badu@git.com> 1777265969 -0700
Fix nav spacing