.gitignore everything by default

📅 Thu, Sep 4, 2025 ⏱️ One-minute read

We’ve all been there. You’re working on a project, making commits, and suddenly realize you’ve been committing .DS_Store files, node_modules, IDE configuration files, or other junk that shouldn’t be in your repository. Then comes the embarrassing cleanup: adding these files to .gitignore, removing them from the repository history, and hoping no one noticed.

This means we’re always playing catch-up with files we didn’t mean to track.

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 looks like in practice for a simple Go project:

1
2
3
4
5
6
*
!.gitignore
!*.go
!README.md
!go.mod
!go.sum

This .gitignore file does exactly that:

  • * - Ignore everything
  • !.gitignore - Except the gitignore file itself
  • !*.go - Except Go source files
  • !go.mod - Except the Go module file
  • !go.sum - Except the Go dependencies file

With this setup, only the files you explicitly allow will ever be tracked by Git. No more accidental commits of system files, build artifacts, or IDE configurations.

Discuss on Hacker News

Feedback

As always, please reach out to me on X with questions, corrections, or ideas!