Sub topic 1
Commits and references: what a tag points to
Prerequisites
This chapter assumes you can commit, branch, push and pull in Git. You should be comfortable in a terminal and have a repository to experiment in. You don't need any tag knowledge yet.
Commits are the fixed points
A commit is a snapshot of your project plus metadata: author, date, message, and the hash of its parent commit. Git identifies each commit by a hash such as 4f2a9c1..., a long hexadecimal string computed from the commit's contents. If the contents change, the hash changes. That makes a hash exact, but hard to remember and awkward to put in release notes.
References are names for hashes
A reference (or ref) is a human-readable name that points to a commit hash. Git stores refs as small files under .git/refs/. You can see them in a repository:
# Show every ref in the repository and the hash it points to
git show-ref
# Show the hash that HEAD resolves to
git rev-parse HEAD
# Show the hash that the main branch points to
git rev-parse mainGit has three kinds of refs you will meet here:
| Ref type | Location | Behavior |
|---|---|---|
| Branch | `refs/heads/` | Moves forward automatically when you commit on it |
| Remote-tracking branch | `refs/remotes/` | Updated when you fetch or pull |
| Tag | `refs/tags/` | Stays where you put it |
HEAD is a special ref that says where you are now. Usually it points to a branch, and that branch points to a commit.
Where a tag fits
A tag is a ref that normally never moves. A branch such as main advances with every new commit. A tag such as v1.0.0 keeps pointing at the same commit, so it gives that exact snapshot a permanent, readable name.
The diagram below shows a branch moving while a tag stays fixed.
You can see this yourself by listing what a ref resolves to:
# Print the commit hash behind a ref name
git rev-parse main
git log --oneline --decorate -3The --decorate option labels each commit with the refs that point at it, so branches and tags appear next to their commits.
Why this matters for releases
Because a tag does not move, anyone who checks out v1.0.0 gets the same code, today or in two years. GitHub Releases, which later chapters cover, attach notes and downloadable files to a tag. The tag supplies the fixed commit, and the release supplies the description.
Exercise
You create the tag v2.0.0 on the latest commit of main, then make three more commits on main. Which commit does v2.0.0 point to, and which does main point to?
Show answer
v2.0.0 still points to the commit it was created on, because tags do not move. main points to the newest of the three new commits, because a branch advances with each commit.