THE GITHTML FIELD GUIDE
Understand Git’s working tree, index, and HEAD
Git compares three useful states: the working tree contains your editable files, the index holds the proposed next snapshot, and HEAD identifies the current commit, usually through a branch. Staging copies selected content into the index. Committing records the index, not every unsaved or unstaged edit in your project.
Treat the index as a snapshot
The staging area is often described as a list of changed files, but that model breaks down when you edit a file twice. The index represents the tracked content proposed for the next commit, including unchanged paths. A staged change is a difference between that proposal and the current commit. Your editor works on a separate copy in the working tree.
Imagine changing a retry limit from two to three, staging the file, and then changing three to four without staging again. The index still contains three. A normal commit records three, while four remains in your working file. This is deliberate: staging lets you prepare one coherent change without committing every experiment.
Ask Git the right comparison
Status summarizes the differences. Plain diff shows working-tree changes relative to the index. Staged diff compares the index with HEAD. Comparing HEAD directly with the working tree combines tracked changes across both layers but does not list the contents of newly untracked files. Run each command separately and identify which copy you are inspecting.
- If a file appears in both staged and unstaged sections, inspect both diffs before deciding which version belongs in the commit.
- When you edit after staging, stage again only if the later edit belongs in that same logical change. Otherwise leave it unstaged.
git status --short
git diff
git diff --staged
git diff HEADUse the model to avoid accidental commits
A file being tracked does not mean its latest edits are committed. Likewise, an empty plain diff does not mean there is nothing to commit: all changes may already be staged. These distinctions matter when an editor shows a modified badge while the terminal appears quiet. Check the index comparison before changing commands or assuming Git lost data.
The working tree is simply your checked-out files; it does not mean you need to create an additional Git worktree. For a normal task, continue in the existing checkout. Before a commit, read the staged diff as the proposed artifact, check for secrets and unrelated edits, and then confirm the new commit’s contents. This gives each state a clear purpose instead of treating staging as an arbitrary hurdle.
Saving in an editor and staging in Git are independent events. Check both when autosave, format-on-save, or another tool changes a file after your review.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.