Theory
Theory: The Add/Commit Cycle is the Product
A repository is useful the moment you can take bytes on disk, choose a subset, and name a snapshot. Everything else (branch, rebase, push) is names and copies of that operation.
Invariants
git initcreates.git/and a symbolicHEAD. The first commit createsrefs/heads/main.git addcopies working-tree bytes into the index (and writes blobs). It does not create a commit.git commitwrites a tree from the index, then a commit, then slides the current branch name.git statusis three comparisons: working vs index, index vsHEAD, untracked vs index.- Undo of uncommitted work is
restore. Undo of the last unpublished commit is--amend. Undo of published history isrevert(later).
edit → add → commit
WD index HEAD / main
status reports which of the three disagree
Why the index exists
Without an index, every commit would be “whatever is on disk.” The index is how you commit two of five edited files, or one hunk of a file (add -p). That is also why .gitignore exists: untracked paths never enter the index unless you force them.
What can break
git add .of.envand secrets (ignore first).git commit -aon a new file (it only auto-stages tracked paths).git initin$HOMEand then every subdirectory looking like a repo.- Amending after someone else fetched that hash.
How to read this chapter
Init, add/commit, status/log/diff, and undo are the loop. The hands-on page is that loop on desk-api. Ignore, interactive add, rm/mv, and “what not to commit” are the same loop with sharper edges.