Chapter DGit basicsPage 4 of 8

Git basics

Validate outputs and schemas

Git stores snapshots of tracked files as commits; the staging area lets you choose exactly which changes form the next snapshot.

~14 minValidation

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

Evaluate the chapter step

Validation asks whether the artifact is correct, not merely whether it completed. 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. Include a deliberately wrong case so the check proves it can fail. A test that never observes a bad result may be checking the wrong thing.

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

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

  1. git status --short uses two columns: the left is staged and the right is unstaged.
  2. git diff inspects unstaged content, while git diff --cached inspects the proposed commit.
  3. git add train.py copies that file's current change into the index; it does not upload anything.
  4. git commit creates local history, and git log -1 identifies 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 repository means initialize the intended folder with git init or 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 FILE and 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 commit has 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

Read every command or statement before running it. The examples deliberately expose intermediate state so a surprising result has somewhere concrete to point.

For the current evaluate 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.

On this page, the practical job is to compare the result with an independent expectation. The running case is an evaluation script and README are being changed together, but only the tested evaluation change should enter the first commit.

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.

Checking tutor…

Continue learning · glossary & guides
  1. Which line or command establishes the current step's most important fact?
  2. What output would reveal that fatal: not a git repository means initialize the intended folder with git init or change into the repository?
  3. Can a new user reproduce a small repository with a focused commit named Add held-out model evaluation and a clean working tree from the stated setup?