Pcornel
Automation · Git

.gitignore

Cheat sheet · https://pcornel.dk/topic.php?topic=5478

Back to the Topic

Answer

.gitignore lists file patterns Git should not offer to track, such as build output and local settings. It does not affect files already committed — remove those with git rm --cached — and it is not a way to protect secrets.

Remember

  • Ignored ≠ untracked automatically; files already in the index remain tracked despite matching a .gitignore rule.
  • .gitignore ≠ secret protection; ignored files can still be read, copied, logged or force-added.
  • Pattern present ≠ pattern matches intended path; anchoring, directory context and negation affect results.
  • File absent from status ≠ file absent from repository history; secrets may remain in prior commits.

First checks

  • cat .gitignore — patterns
  • git check-ignore -v <file> — why ignored
  • git status --ignored — ignored files

Verify in this order

file → ignore rules → not tracked

Where it usually breaks

An ignore match proves Git will normally suppress an untracked path from discovery; it does not untrack existing content, erase history or secure sensitive data.

Input/desired state → request accepted → job/task terminal status → target object read-back → effective runtime state → original workload → regression/rollback readiness.

.gitignore Git boundary map

BoundaryHealthy evidenceSuspicious evidence
Local stateRepository, HEAD, worktree/index and commit IDs are explicitWrong repo/ref, hidden staged/untracked state or mutable-name ambiguity
History / refsAncestry and branch/tag movement match intentUnexpected rewrite, stale tracking ref or unclear merge base
Remote syncURL/refspec, auth and remote read-back match expected commitsLocal assumptions, rejection, stale fetch or unsafe force update
Downstream proofBuild/reconciliation/target is verified independentlyPush/tag/merge success treated as deployment success

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5478

Confirmation

Confirm action

Continue?