A recent Hacker News thread on the article ".gitignore Everything by Default" drew 83 points and 97 comments. The core recommendation is to begin every .gitignore with a single * line that ignores all files, then explicitly whitelist only the files a project needs.
What It Is / How It Works
The pattern starts with * to block everything. Subsequent lines use ! to re-include specific paths such as source code, configuration templates, and small documentation files. Git still tracks the .gitignore itself, so the whitelist remains under version control.
This approach forces every new file to be added deliberately. In AI repositories it prevents accidental commits of multi-gigabyte model weights, cached datasets, or intermediate training artifacts.
Benchmarks / Specs / Numbers
The HN thread logged 83 upvotes and 97 comments within the first 48 hours. Commenters cited repository sizes ranging from 12 GB to 180 GB that shrank to under 50 MB after switching to the whitelist strategy. One user reported a 94 % reduction in clone time on a 40 GB diffusion-model repo.
How to Try It
Create or replace the root .gitignore with these lines:
*
!.gitignore
!README.md
!requirements.txt
!src/
src/**
!src/**/*.py
Run git add . followed by git status to verify only the intended files appear. Commit the .gitignore first so the rule set is enforced for the entire team.
Pros and Cons
- Prevents large binary files from entering history
- Makes onboarding clones faster for new contributors
- Requires explicit maintenance of the whitelist when new file types are added
- Can hide legitimate generated files if the whitelist is incomplete
Alternatives and Comparisons
| Strategy | File size control | Maintenance effort | Clone speed | Best for |
|---|---|---|---|---|
| .gitignore everything | High | Medium | Fast | AI/ML repos with binaries |
| Selective ignore patterns | Medium | Low | Medium | Small web projects |
| Git LFS + selective rules | High | High | Slow | Teams already using LFS |
Who Should Use This
Teams shipping large language models, diffusion checkpoints, or scraped datasets benefit most. Skip the pattern if your repository contains only hand-written source files under 100 MB total and changes infrequently.
Bottom Line / Verdict
The whitelist-first .gitignore reduces accidental bloat and speeds up every clone and CI run for AI projects that routinely exceed tens of gigabytes.
Top comments (0)