Skip to main content
Module 1 · Lesson 2 of 52/34 in the course~16 min
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 StatePresent in HEAD?Present in Index?Working vs IndexNext git commit captures...
Untracked (??)NoNoNew on diskIgnored until git add
Staged new (A )NoYesMatches IndexIncluded in next snapshot
Modified unstaged ( M)YesYes (old version)Differs on diskOld Index version, not disk edit
Modified staged (M )YesYes (new version)Matches IndexNew updated version
Split state (MM)YesYes (v2)Working has v3Only 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.

Bash
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 path

Example 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.

Bash
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).

Bash
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.

Bash
git add .
git commit -m "feat: update server port and initialize config"
git status            # nothing to commit, working tree clean
Practice Stage

Step 1 — Initialize and stage selectively

Exercise#git.m1.l2.e1
Attempts: 0Loading…

Initialize the Git repository, stage ONLY README.md into the Index while keeping src/app.ts untracked, and check git status.

Loading editor…
Show hint

Run git init first, then git add README.md (not git add .), followed by git status.

Solution available after 3 attempts

Practice Stage

Step 2 — Stage modified and untracked files cleanly

Exercise#git.m1.l2.e2
Attempts: 0Loading…

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.

Loading editor…
Show hint

Stage all pending files with git add . and save the commit using git commit -m "...".

Solution available after 3 attempts

Practice Stage

Step 3 — Commit one change while holding the second staged

Exercise#git.m1.l2.e3
Attempts: 0Loading…

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.

Loading editor…
Show hint

Sequence: git add src/server.ts -> git commit -m "..." -> git add src/config.ts -> git status -s.

Solution available after 3 attempts

Git Quiz#git.m1.l2.e4
Ready

What does the two-letter prefix 'MM src/api.ts' mean in git status -s output?

Bash
$ git status -s
MM src/api.ts
Answer options
Git Quiz#git.m1.l2.e5
Ready

Suppose 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?

Answer options