GitHub basics
Add observability and tests
Github hosts git repositories and adds pull requests, reviews, checks, and permissions around shared branches.
Before you start
Why this matters
Before running anything, predict one observable result from the case: a branch named improve-evaluation contains one reviewed change that must pass tests before it reaches main. 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.
Merge with the repository's chosen strategy only after review. Then update local main, delete the feature branch when appropriate, and verify the merged commit or squash commit is present.
Read
Run the working example
git switch -c improve-evaluation
python -m pytest
git add train.py tests/test_train.py
git commit -m "Test held-out evaluation"
git push -u origin improve-evaluation
git status -sb
Expected evidence:
2 passed in 0.08s
branch 'improve-evaluation' set up to track 'origin/improve-evaluation'.
Read
improve-evaluation...origin/improve-evaluation
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 switch -ccreates and checks out a local feature branch.pytestsupplies evidence before publication; a successful push is not proof that code works.git push -u origin ...sends commits and records the upstream branch.- the pull request is created on GitHub after the branch exists; pushing does not merge it.
These lines form one chain: local commits on improve-evaluation plus the repository's pull-request rules becomes a remote feature branch and a reviewable proposal into main. 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:
remote origin already existsmeans inspectgit remote -vinstead of adding a duplicate. Re-run the smallest command that proves the repair. - Second failure: a rejected non-fast-forward push usually means the remote branch moved; fetch and reconcile rather than force-pushing shared history. Preserve the failing input as a test when it represents a realistic mistake.
- Misleading success: a red required check must be opened and read; rerunning without a code or infrastructure reason hides the actual failure. 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 a branch named improve-evaluation contains one reviewed change that must pass tests before it reaches main.
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 narrow pull request with a useful summary, reproducible test steps, and a green required check.
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 red required check must be opened and read?
- Can a new user reproduce a narrow pull request with a useful summary, reproducible test steps, and a green required check from the stated setup?