I think we’ve all been there. You’re working on a project, making commits, and then suddenly realize you’ve been committing .DS_Store files, node_modules, IDE configuration files, or other junk (CLAUDE.md for example) that shouldn’t be in your repository. Or even worse - environment variables. Then comes the embarrassing cleanup: adding these files to .gitignore, removing them from the repository history, and hoping that no one has noticed.
What if we flipped this approach entirely? Instead of allowing everything by default and selectively ignoring files, what if we ignored everything by default and only allowed specific files?
Here’s what this could look like in practice for a simple Go project:
* !.gitignore !*.go !README.md !go.mod !go.sum
This .gitignore file does exactly that:
* - Ignore everything
But not these files...
!.gitignore - the gitignore file itself
!*.go - Go source files
!go.mod - Go module file
... continue reading