cd /news/developer-tools/gitignore-everything-by-default · home topics developer-tools article
[ARTICLE · art-121559] src=packagemain.tech ↗ pub= topic=developer-tools verified=true sentiment=· neutral

.gitignore everything by default

A developer proposes flipping the default .gitignore strategy to ignore all files and explicitly allow only those needed, using patterns like '*' followed by '!*.go' to prevent accidental commits of local junk such as .DS_Store, node_modules, or environment files. The technique is presented as an alternative for repositories with excessive local clutter, citing a 207-line .gitignore from Microsoft's typescript-go project as motivation, and suggests using 'git check-ignore -v' to debug ignored paths.

read1 min views2 publishedSep 5, 2026
.gitignore everything by default
Image: Packagemain (auto-discovered)

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
  • !go.sum - Go dependencies file
  • anything else you wish to include

With this setup, only the files you explicitly allow will be tracked by Git. No more accidental commits of unintended local files.

The technique isn’t necessarily the right choice for every repository or developer, but is an alternative to explore.

Nowadays, I see that projects have so much crap locally, like various agentic docs or subfolders, so it may seem easier to just ignore everything at first.

Just look at this 207-lines .gitignore from typescript-go.

p.s. if you want to check if the path is ignored by git, you can run this command:

git check-ignore -v internal/server/server.go

This can save a lot of head-scratching when a file you expected to track doesn’t appear in Git.

p.s. have you heard of lazygit? The best Git TUI out there, check it out.

── more in #developer-tools 4 stories · sorted by recency
── more on @microsoft 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/gitignore-everything…] indexed:0 read:1min 2026-09-05 ·