A ref is a name that resolves to a commit hash. Three kinds:
-
Direct refs — a file under .git/refs/ containing a 40-char hash.
refs/heads/main — local branch.
refs/tags/v1.0 — tag.
refs/remotes/origin/main — remote-tracking branch.
-
Symbolic refs — a file containing ref: <other-ref>. The most important is .git/HEAD, usually pointing at the current branch.
-
Special refs — ORIG_HEAD, FETCH_HEAD, MERGE_HEAD, CHERRY_PICK_HEAD — Git writes these during operations so you can reference them.
Resolve any ref:
git rev-parse main # main's commit hash
git rev-parse HEAD # current commit
git rev-parse @{u} # upstream of current branch
git rev-parse main^ # main's parent
git rev-parse 'main@{yesterday}' # main as of yesterday
Refs are cheap — they're just files. You can create your own under any namespace.