Flip Your .gitignore: Block Everything, Then Whitelist What Belongs
The conventional .gitignore is a blocklist — commit everything by default, then scramble to exclude junk like .DS_Store, node_modules, IDE configs, or worse, leaked environment variables. The author proposes inverting that logic: ignore everything with a single *, then explicitly re-include only the files you want tracked using negation patterns (!*.go, !go.mod, !README.md, and so on).
The payoff is that accidental commits become structurally impossible rather than a discipline problem. Any new local file — build artifacts, editor settings, or the growing pile of agentic tooling docs and scratch folders that clutter modern repos — stays untracked unless you deliberately add an allow rule. The author contrasts this tidy whitelist against sprawling blocklists like the 207-line .gitignore in the typescript-go project.
This isn’t presented as a universal best practice; it suits repos with a small, predictable set of tracked file types more than sprawling polyglot codebases where maintaining the allow-list becomes its own chore. Two practical asides: use git check-ignore -v <path> to debug why an expected file isn’t being tracked, and the author plugs lazygit as a terminal Git UI.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.