HeadlinesBriefing favicon HeadlinesBriefing.com

Gitignore Everything by Default for Go Projects

Hacker News •
×

Many developers have accidentally committed . DS_Store files, node_modules, IDE configs, or environment variables, leading to embarrassing cleanups. Instead of allowing everything by default and selectively ignoring files, consider ignoring everything by default and only allowing specific files.

For a simple Go project, a .gitignore file can ignore everything except key files: .gitignore itself, *.go source files, go.mod, go.sum, and any other explicitly allowed files. This ensures only intended files are tracked by Git. The technique isn't ideal for every repository but offers an alternative approach.

Modern projects often contain numerous local files like agentic docs or subfolders, making it easier to ignore everything initially. A 207-line .gitignore from typescript-go demonstrates this complexity. To check if a path is ignored by git, run git check-ignore <file>.

This can prevent confusion when expected files don't appear in Git. Additionally, lazygit is recommended as the best Git TUI available.