Human-Readable Pointers
Git's internal database uses 40-character SHA-1 hashes to identify everything. Humans use names like main, develop, or v2.0. References (refs) bridge this gap.
A ref is simply a text file containing a commit hash. That's it. The file ~/.git/refs/heads/main might contain nothing more than:
c3f4a1b2d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0
When you run git checkout main, Git reads that file, gets the hash, and checks out that commit. When you make a new commit on main, Git updates that file with the new hash.
Types of Refs
1. Heads (Branches)
A branch is a pointer to the latest commit in a line of development. When you make a new commit, the branch pointer automatically advances to the new commit. Branches are intentionally cheap — creating one just creates a new 41-byte file.
2. Tags
A tag is a pointer to a specific commit, typically used to mark release versions. Unlike branches, tags do not move when you make new commits. There are two kinds:
- Lightweight tag: Just a ref file pointing to a commit. Identical to a branch, but by convention it doesn't move.
- Annotated tag: A full Git object with its own hash, containing a message, tagger identity, and optionally a GPG signature. Use annotated tags for releases.
3. Remote-Tracking Refs
These are read-only pointers representing the last known state of branches on a remote server. You cannot move them directly. They update when you run git fetch or git push.
4. HEAD
HEAD is a special ref that points to your currently checked-out branch (or directly to a commit in "detached HEAD" state). It's the answer to "where am I right now?" — and, like every other ref, it's just a small text file, this one containing either the path to the branch it's currently following or a raw commit hash if detached.
Key Point: Refs are lightweight text files containing commit hashes. Branches are mutable refs that advance with new commits. Tags are (by convention) immutable refs. Remote-tracking refs are read-only snapshots of remote state. HEAD is the special ref that tracks your current position.