Example keys from a provider’s documentation are deliberately ignored by scanners; test with a randomly generated string.
Do
Command or place
keep the real settings file out
.env in .gitignore; commit .env.example instead
scan what is staged
trufflehog git file://. --since-commit HEAD --fail (exit 183 when something is found)
scan the whole history
trufflehog git file://. (add --results=verified,unknown to see only live or uncheckable credentials)
run the scan on every commit
.githooks/pre-commit plus git config core.hooksPath .githooks; git add, then git commit, never -am
one already got in
rotate it first; then git filter-repo --invert-paths --path FILE --force; then git push --force-with-lease origin BRANCH for every branch git branch -r lists; collaborators re-clone
Settings, Rulesets, New ruleset, New branch ruleset; Enforcement status Active; target the default branch
the rules
Require a pull request before merging; Block force pushes; Restrict deletions; Require status checks to pass; Require signed commits; Require linear history
a check to require
.github/workflows/ci.yml with permissions: contents: read and your test command, on pull_request
owners for the files that matter
.github/CODEOWNERS
Reading a pull request (chapter 7)
Shape first (files, lines, commits, description). Then manifests and lockfiles, anything under .github/, config, binaries, weakened tests. Then the stop patterns: key-shaped strings, new hosts, encoded blobs, new reads of env or network, refactors that add behaviour. gh pr checkout N, run it. Review comments that are specific, ask before asserting, and say what you ran.
When it goes wrong (chapter 8)
The mistake
The rung
bad edit, not staged
git restore file
staged by accident
git restore --staged file
last commit wrong, not pushed
git commit --amend
commit wrong, already pushed
git revert <id>
my own branch, go back an hour
git reset --hard <id>; git reflog to find your way back
deleted a branch
git reflog, then git branch name HEAD@{n}
force push
never to main; only your branch; always --force-with-lease
GitHub hygiene (chapter 9)
Do
Place
second factor
Settings, Password and authentication, Enable two-factor authentication; download the recovery codes; add a passkey
a token for a script
Settings, Developer settings, Personal access tokens, Fine-grained tokens: name, expiry, only select repositories, least permissions