Git basics
Cover security and operational gates
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
Operate the chapter step
Operational quality includes safe inputs, predictable resources, and recoverable changes. 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. Review what is written to disk or logs, which dependencies execute, and what another user can alter.
Read every command or statement before running it. The examples deliberately expose intermediate state so a surprising result has somewhere concrete to point.
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 input contract is the working-tree versions of train.py and README.md. The visible result is a commit containing the intended train.py diff while the README edit remains unstaged.
For the current operate 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.
Use git show --stat --oneline HEAD and git show HEAD -- train.py. Success means the commit names one coherent change, contains no credential or generated environment, and leaves only the deliberate README edit in the 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
fatal: not a git repositorymeans initialize the intended folder withgit initor change into the repository? - 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?