Module lessons (2/5)
Initializing repositories & staging changes
Tracking Files Inside .git
Right after git init, your repository has zero commits (HEAD points to an unborn main branch), yet the .git database is immediately ready to track files.
Every path in your working folder sits in one of two families reported by git status:
| File Lifecycle State | Present in HEAD? | Present in Index? | Working vs Index | Next git commit captures... |
|---|---|---|---|---|
Untracked (??) | No | No | New on disk | Ignored until git add |
Staged new (A ) | No | Yes | Matches Index | Included in next snapshot |
Modified unstaged ( M) | Yes | Yes (old version) | Differs on disk | Old Index version, not disk edit |
Modified staged (M ) | Yes | Yes (new version) | Matches Index | New updated version |
Split state (MM) | Yes | Yes (v2) | Working has v3 | Only v2 unless re-staged |
Inspect Area Transitions Visually
Interact with edits, staging (git add), unstaging (git restore --staged), and committing inside the Four Areas simulator:
Example 1 — Compact Two-Column Output with git status -s
Short status uses two columns: the left column shows Staging Index status and the right column shows Working Tree status.
git status -s
# M src/server.ts -> left col blank, right col M (modified, NOT staged)
# M src/server.ts -> left col M, right col blank (staged in Index)
# ?? src/config.ts -> untracked pathExample 2 — Selective Staging vs git add .
When fixing two things at once, naming an explicit file (git add src/server.ts) isolates that change inside the Index without sweeping untracked drafts in.
git add src/server.ts
git status -s
# M src/server.ts (ready for commit)
# ?? src/config.ts (untouched in Working Tree)Example 3 — Updating Everything Already Tracked with git add -u
If you want to stage edits to tracked files without accidentally picking up brand-new untracked files, use --update (-u).
git add -u # Stages modified/deleted tracked files only
git status -s # Untracked files remain '??'Example 4 — Committing Staged Snapshots with -m
Once git status confirms the intended files live under Changes to be committed, seal the snapshot cleanly with an explicit message.
git add .
git commit -m "feat: update server port and initialize config"
git status # nothing to commit, working tree cleanStep 1 — Initialize and stage selectively
Initialize the Git repository, stage ONLY README.md into the Index while keeping src/app.ts untracked, and check git status.
Show hint
Run git init first, then git add README.md (not git add .), followed by git status.
Solution available after 3 attempts
Step 2 — Stage modified and untracked files cleanly
Stage both the modified src/server.ts and untracked src/config.ts using git add ., then commit so the Working Tree and Index are completely clean.
Show hint
Stage all pending files with git add . and save the commit using git commit -m "...".
Solution available after 3 attempts
Step 3 — Commit one change while holding the second staged
Stage and commit src/server.ts by itself first, then stage src/config.ts into the Index (without committing it yet) and run git status -s.
Show hint
Sequence: git add src/server.ts -> git commit -m "..." -> git add src/config.ts -> git status -s.
Solution available after 3 attempts
What does the two-letter prefix 'MM src/api.ts' mean in git status -s output?
$ git status -s
MM src/api.tsSuppose dirty-staging contains a modified tracked file (src/server.ts) and an untracked draft (src/notes.tmp). Which command stages ONLY tracked edits while leaving src/notes.tmp untracked?