Skip to content
Tech News
← Back to articles

.gitignore Everything by Default

read original get Pro Git (2nd Edition) by Scott Chacon → more articles
Why This Matters

This article introduces a radical approach to managing Git repositories by ignoring all files by default and explicitly allowing only specific ones. This method can help developers prevent accidental commits of unwanted files, streamlining project management and improving repository cleanliness. While not suitable for every project, it offers a valuable alternative for maintaining a tidy codebase and reducing errors.

Key Takeaways
Worth a Look

Pro Git (2nd Edition) by Scott Chacon — If .gitignore tricks like allowlisting everything intrigue you, Pro Git is the canonical reference that walks through ignore patterns, history rewriting, and cleaning up those accidental commits. It's a great desk companion for anyone who wants to stop fighting Git and start using it deliberately.

See Pro Git (2nd Edition) by Scott Chacon on Amazon → Affiliate link — we may earn a commission on purchases, at no extra cost to you. Product picked by AI based on this article; it is not a tested recommendation.

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