.gitignore Everything by Default
Adopting a "Deny-All" Strategy for .gitignore
By Alex Pliutau | September 05, 2026

We have all experienced this specific frustration. You are deep in the flow of a project, pushing commits regularly, only to realize you've accidentally leaked "repository junk" into your version control.
Common culprits include:
.DS_Store(macOS system files)node_modules(massive dependency folders)- IDE-specific configuration files
- Miscellaneous clutter like
CLAUDE.md
"Then comes the embarrassing cleanup: adding these files to
.gitignore, removing them from the repository history, and hoping that no one has noticed."
Flipping the Script
Traditionally, we use a "whitelist" approach where everything is permitted unless explicitly forbidden. This is the standard way. However, what if we inverted that logic? Instead of selectively ignoring files, we could ignore everything by default and only permit specific, necessary files.
Practical Implementation: A Go Project Example
If you were applying this "inverse" logic to a basic Go project, your .gitignore file would look like this:
# Ignore everything by default
*
# But allow these specific files...
!.gitignore
!*.go
!README.md
!go.mod
!go.sum
Breakdown of the Logic:
| Pattern | Meaning |
|---|---|
* | Global Ignore: Tells Git to ignore every single file. |
!.gitignore | Exception: Ensure the ignore file itself is tracked. |
!*.go | Exception: Track all Go source files. |
!go.mod / !go.sum | Exception: Track module and dependency definitions. |
!README.md | Exception: Track the project documentation. |

The Conceptual Shift
Mathematically, we are changing the set of tracked files from a subtraction problem to an intersection problem:
Here is how the logic flow differs:
Why do this now?
This technique isn't a universal requirement for every developer or every single repo, but it is a powerful alternative. In the modern development landscape, our local environments are increasingly cluttered with agentic documentation, temporary subfolders, and AI-generated artifacts. Starting with a "blank slate" is often simpler than playing "whack-a-mole" with junk files.
The "Cleanup" Checklist
If you've already committed junk, your workflow usually looks like this:
- Identify the offending files.
- Add them to
.gitignore. - Run
git rm --cached <file>to remove them from the index. - Commit the changes.
Troubleshooting
When you use a "deny-all" strategy, you might occasionally wonder why a specific file isn't appearing in your git status. To stop the head-scratching, you can use the following inline command to debug the ignore path:
git check-ignore -v internal/server/server.go
# Example output showing which line of .gitignore is causing the ignore
.gitignore:1:* internal/server/server.go
![]()