Frequently Asked Question

What are refs, branches, and tags really?

Under the bonnet, a ref is just a file on disk under .git/refs/ whose contents are a 40-character commit hash. A branch named main is the file .git/refs/heads/main; a tag named v1.0 is the file .git/refs/tags/v1.0; the last fetched state of a remote branch is .git/refs/remotes/origin/main. That is genuinely all there is to it. cat .git/refs/heads/main will print the commit your local main is currently at.

The difference between a branch and a lightweight tag is convention, not structure: branches are expected to move forward when you commit on them; tags are expected to stay fixed, marking a release or other historical point. An annotated tag (git tag -a v1.0 -m "Release 1.0") is slightly heavier, it creates a tag object with author, date, and message, separate from the commit it points to. Use annotated tags for anything you want to be permanent.

Video

Further reading and video