Git basics
Add observability and tests
Git stores snapshots of tracked files as commits; the staging area lets you choose exactly which changes form the next snapshot.
Before you start
Why this matters
Before running anything, predict one observable result from the case: an evaluation script and README are being changed together, but only the tested evaluation change should enter the first commit. Write the prediction beside the command or code line that should cause it. This makes the session an experiment rather than a transcription exercise.
1Learn the idea
Read
Test the chapter step
Turn the stable example into repeatable checks. Capture the command, input fixture, expected output, and important boundary. Tests should be fast enough to run before every change and precise enough that a failure identifies behavior rather than just saying the chapter broke.
Share the commit hash and the exact verification command. A teammate should be able to inspect the patch with git show HASH, run the relevant test, and understand why the snapshot exists.
Read
Run the working example
git status --short
git diff -- train.py
git add train.py
git diff --cached
git commit -m "Add held-out model evaluation"
git log -1 --oneline
Expected evidence:
M train.py
M README.md
[main a1b2c3d] Add held-out model evaluation
1 file changed, 6 insertions(+)
The output may include version-specific details such as hashes, paths, fitted thresholds, or final decimal places. Compare the structural facts described here rather than copying placeholders. If the structure differs, stop and inspect the earliest unexpected line.
Read
Read it line by line
git status --shortuses two columns: the left is staged and the right is unstaged.git diffinspects unstaged content, whilegit diff --cachedinspects the proposed commit.git add train.pycopies that file's current change into the index; it does not upload anything.git commitcreates local history, andgit log -1identifies the resulting snapshot.
These lines form one chain: the working-tree versions of train.py and README.md becomes a commit containing the intended train.py diff while the README edit remains unstaged. Change only one input first. When several values change together, you cannot tell which change caused the new behavior.
Read
Common errors and fixes
- First failure:
fatal: not a git repositorymeans initialize the intended folder withgit initor change into the repository. Re-run the smallest command that proves the repair. - Second failure: an accidental staged secret must be removed from the index with
git restore --staged FILEand from the file before committing. Preserve the failing input as a test when it represents a realistic mistake. - Misleading success: a commit that says
nothing to commithas no staged changes; inspect both status columns instead of repeating the command. A clean-looking final line cannot cancel contradictory intermediate evidence.
When debugging, copy the exact error text and inspect names, paths, shapes, types, and versions. Explain the cause in one sentence before changing code. That discipline prevents a guessed repair from creating a second defect.
Read
Evidence for this stage
On this page, the practical job is to turn important behavior into repeatable checks. The running case is an evaluation script and README are being changed together, but only the tested evaluation change should enter the first commit.
For the current test step, save the smallest useful evidence: the relevant command, its output, and the input that produced it. Do not use a screenshot as the only record when text can be copied and searched. Keep generated artifacts separate from source inputs so rerunning the example does not destroy the evidence it is meant to evaluate.
The deliverable for this step is a small repository with a focused commit named Add held-out model evaluation and a clean working tree.
Read
Reflect on the result
Return to your opening prediction. Mark it correct or rewrite it with the condition you missed. Then explain the difference between a successful execution and a trustworthy result for this specific example.
Continue learning · glossary & guides
- Which line or command establishes the current step's most important fact?
- What output would reveal that a commit that says
nothing to commithas no staged changes? - Can a new user reproduce a small repository with a focused commit named
Add held-out model evaluationand a clean working tree from the stated setup?