Refs & HEAD
You run git switch dev and every file in your project changes at once, yet not a single saved commit has moved. Something tiny on disk got rewritten, and finding it explains why branching costs almost nothing.
- ▸A branch is a 41-byte file: one commit hash and a newline. That is the whole thing.
- ▸Switch branches and your files change, yet not one saved commit moves; only a tiny file recording where you are.
- ▸The scary "detached HEAD" state is only that file holding a bare hash, not a branch name.
Switch to another branch and your files rearrange in an instant. Nothing about your saved history moved, though, so what did the command actually touch? Open the folder git keeps beside your code, in .git/, and look at the file that stands in for your current branch. It holds one line: a 40-character string like b6dabde965461c296544edf7c84341cc7984e62f, and nothing else. That string is the name of a commit, the exact object you met last topic. A branch, the thing you pictured as a container holding all your work, is a single line pointing at one commit.
One caveat before you go looking: after git gc or git pack-refs (which git can run on its own), git may fold these loose files into a single .git/packed-refs file. If cat .git/refs/heads/main then reports the file missing, the branch is not gone, it moved into packed-refs, still one line, just relocated. git rev-parse main prints the hash either way.