What is a Ref

A ref (reference) is a pointer from a human-readable name to a Git commit hash. Instead of remembering a1b2c3d4e5f6..., you use main or v1.0. Refs are stored as plain text files in .git/refs/.

How it works

A ref file contains a single line: the 40-character SHA-1 hash of a commit. When Git resolves a ref (e.g., git log main), it reads the file .git/refs/heads/main and uses the hash inside.

Refs are organized by type:

  • .git/refs/heads/ — local branches
  • .git/refs/tags/tags
  • .git/refs/remotes/remote-tracking branches

A symbolic ref points to another ref instead of a hash. HEAD is typically a symbolic ref: ref: refs/heads/main. This indirection is how Git knows which branch to advance when you commit.

As repositories grow, Git packs many refs into a single .git/packed-refs file for efficiency. The behavior is identical — just fewer filesystem lookups.

Why it matters

Refs are what make Git usable. Without them, you would need to memorize 40-character hex strings. Branches, tags, and remotes are all just refs — lightweight pointers that Git can create, move, and delete in O(1).

See How Git Branching Works for how refs enable free branching.