Branch References
What
A branch is simply a text file on your disk containing the 40-character SHA-1 hash of the commit it points to. Git organizes these branch pointers under the .git/refs/heads/ directory.
How
You can inspect the files representing your branches directly through your operating system’s standard terminal commands:
# List all files inside the refs/heads directory
ls .git/refs/heads/
# Output includes: main, add_classics
# Read the contents of the 'main' branch file
cat .git/refs/heads/main
# Output: 5ba786fcc93e8092831c01e71444b9baa2228a4f (the exact commit hash!)
Why
Peeking inside .git/refs/heads/ demystifies how Git manages branches. Rather than utilizing a complex, heavy binary database or duplicating large volumes of project files, Git maintains branches via plain text files containing a single commit hash. When you switch branches or make a commit, Git simply updates the string of characters inside these tiny files.
Summary
Git stores branches as simple, plain-text reference files under .git/refs/heads/, where each file is named after the branch and contains the 40-character SHA-1 hash of its current commit tip.