logo
Kurashizu Blogwhere ideas flow
  • Home
  • News
  • Blog
  • About
  • Home
  • News
  • Blog
  • About

© 2026 Kurashizu. All rights reserved.

Admin·New Post·Service Status
Powered by Cloudflare·31.10.26
← Back to news

.gitignore Everything by Default

Original article
packagemain.tech|76 points|80 comments|by der_gopher|Sep 5, 2026

Adopting a "Deny-All" Strategy for .gitignore

By Alex Pliutau | September 05, 2026

Header Image

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:

PatternMeaning
*Global Ignore: Tells Git to ignore every single file.
!.gitignoreException: Ensure the ignore file itself is tracked.
!*.goException: Track all Go source files.
!go.mod / !go.sumException: Track module and dependency definitions.
!README.mdException: Track the project documentation.

Logo

The Conceptual Shift

Mathematically, we are changing the set of tracked files StrackedS_{tracked}Stracked​ from a subtraction problem to an intersection problem:

Standard: Stracked=Sall−Signored\text{Standard: } S_{tracked} = S_{all} - S_{ignored}Standard: Stracked​=Sall​−Signored​ Inverse: Stracked=Sall∩Sallowed\text{Inverse: } S_{tracked} = S_{all} \cap S_{allowed}Inverse: Stracked​=Sall​∩Sallowed​

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

Author Icon User