{"slug": "gitignore-everything-by-default", "title": ".gitignore everything by default", "summary": "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.", "body_md": "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.\n\nWhat 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?\n\nHere’s what this could look like in practice for a simple Go project:\n\n```\n*\n!.gitignore\n!*.go\n!README.md\n!go.mod\n!go.sum\n```\n\nThis `.gitignore` file does exactly that:\n\n- `*` - Ignore everything\n\nBut not these files...\n\n- `!.gitignore` - the gitignore file itself\n- `!*.go` - Go source files\n- `!go.mod` - Go module file\n- `!go.sum` - Go dependencies file\n- anything else you wish to include\n\nWith this setup, only the files you explicitly allow will be tracked by Git. No more accidental commits of unintended local files.\n\nThe technique isn’t necessarily the right choice for every repository or developer, but is an alternative to explore.\n\nNowadays, 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.\n\nJust look at [this 207-lines .gitignore](https://github.com/microsoft/typescript-go/blob/main/.gitignore) from typescript-go.\n\np.s. if you want to check if the path is ignored by git, you can run this command:\n\n```\ngit check-ignore -v internal/server/server.go\n```\n\nThis can save a lot of head-scratching when a file you expected to track doesn’t appear in Git.\n\np.s. have you heard of [lazygit](https://github.com/jesseduffield/lazygit)? The best Git TUI out there, check it out.", "url": "https://wpnews.pro/news/gitignore-everything-by-default", "canonical_source": "https://packagemain.tech/p/gitignore-everything-by-default", "published_at": "2026-09-05 13:19:28+00:00", "updated_at": "2026-09-07 01:59:40.980320+00:00", "lang": "en", "topics": ["developer-tools"], "entities": ["Microsoft", "typescript-go", "lazygit", "Git"], "alternates": {"html": "https://wpnews.pro/news/gitignore-everything-by-default", "markdown": "https://wpnews.pro/news/gitignore-everything-by-default.md", "text": "https://wpnews.pro/news/gitignore-everything-by-default.txt", "jsonld": "https://wpnews.pro/news/gitignore-everything-by-default.jsonld"}}