A ref is a name that points to a commit. Branches and tags are refs. They live as small text files under .git/refs/.
cat .git/refs/heads/main → a 40-char SHA-1. That's it.
HEAD is special: it's a symbolic ref, usually pointing at a branch name rather than a commit. cat .git/HEAD typically shows:
ref: refs/heads/main
When you commit, Git updates the branch HEAD points to. When you git switch other-branch, HEAD is rewritten to point at that branch. When you check out a specific commit (git checkout abc123), HEAD points directly at the commit — that's "detached HEAD".
Commands that take a ref accept any name: branch, tag, HEAD, HEAD~3, main@{yesterday}, or a raw hash. They all resolve to the same place: a commit.