Reading a Branch's Raw File
cat .git/refs/heads/master
cat .git/refs/heads/spicy-experiments
Each file's entire content is one 40-character SHA-1 hash — the exact commit that branch currently points at. Nothing else is stored there.
Confirming Against git's Own Output
git rev-parse spicy-experiments
The exact same hash the file contains. git rev-parse simply reads that file (or resolves other kinds of references the same way) — it is not consulting some separate, hidden source of truth.
Creating a Branch by Hand
git rev-parse spicy-experiments > .git/refs/heads/manual-branch
git branch
No git branch command was used to create it — a plain shell redirect into a new file inside .git/refs/heads/ was enough. git's own git branch listing shows it anyway, because that is genuinely all a branch is.
Every branch you have ever created or heard of — master, spicy-experiments, or any team's feature branch — is genuinely nothing more than a file inside .git/refs/heads/ containing one commit hash. Moving a branch (a commit, a checkout, a reset) is really just git rewriting that one file.
This lesson proves it directly: read the real files, confirm they match git rev-parse's own output, then create a working branch by literally writing a hash into a new file yourself — no git command required to create it, and git accepts it as a genuine branch anyway.
refs/heads
The real directory inside .git/ where every local branch is stored, one file per branch, each file's content being exactly the commit hash that branch points at. Confirmed directly in this lab by reading the files themselves.
git rev-parse
Resolves any reference (a branch name, HEAD, a partial hash) to its full, real commit hash. When pointed at a branch, it genuinely reads the same file cat can read directly — confirmed by comparing the two outputs side by side in this lab.
Takeaways
- .git/refs/heads/<name> is a real file whose entire content is one commit hash — nothing more is stored there
- git rev-parse <branch> genuinely reads that exact same file — there is no separate, hidden branch registry
- A branch can be created with a plain file write; git only cares that the file exists and holds a valid hash
- This is why creating a branch is instant and free — it is a few bytes of text, never a copy of the project
- Understanding this removes a real layer of "black box" anxiety around how branches actually work