Git basics
Mastery: ship checklist
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
Ship the chapter step
Shipping means handing off evidence, not only source code. 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. Rebuild or rerun from the documented starting point. If another person needs an undocumented fact from your machine, the handoff is incomplete.
Keep the example small enough to inspect manually. Small does not mean careless: boundary values, file locations, feature order, and held-out data still determine whether the result means what you claim.
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
The deliverable for this step is a small repository with a focused commit named Add held-out model evaluation and a clean working tree.
For the current ship 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.
Keep .venv/, .env, model binaries, and private datasets in .gitignore. Git history is not a secret store: removing a key in a later commit does not remove it from earlier objects.
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 an accidental staged secret must be removed from the index with
git restore --staged FILEand from the file before committing? - 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?