Ignore rules are ordered rules
Combine build patterns carefully and remember that ignoring a file does not remove its history.
Understand the scope of an ignore file
A .gitignore tells Git about intentionally untracked paths to omit from normal tracking. It is not a firewall, backup policy or secret scanner. A file that is already tracked stays tracked until you explicitly change the index.
Patterns are relative to the applicable ignore file and follow Git’s path and directory semantics. A trailing slash denotes directories. Test important matches with git check-ignore -v so the winning rule and source file are visible.
node_modules/ .env* !.env.example
Preserve exception order
A later negation can re-include a path previously excluded, subject to parent-directory restrictions. A later exclusion can reverse that negation again. Globally sorting or deduplicating every rule can therefore change behavior.
This generator removes duplicate bundled patterns when combining templates, but preserves your custom section’s exact order and repeated rules. Keep complicated negations in that custom section and inspect the resulting file before committing it.
Use a deliberate project baseline
The bundled templates are small, independently authored CC0 selections for common build and editor artifacts. They do not claim to cover every framework configuration. Cargo.lock is intentionally not ignored because applications commonly commit it; decide the right policy for your repository.
If a real credential was committed, adding its filename to .gitignore is insufficient. Rotate the credential, remove tracked copies where appropriate and review the repository’s history-handling process. Never assume deleting the visible file retracts earlier copies or downstream access.
Keep one log file while ignoring the rest
Combine Node patterns with an ordered exception before adding generated fixtures or local environment files to a repository.
Input
Template: Node Custom patterns: *.log !keep.log
Expected output
# Generated locally. Review ordering and negation before use. # Node node_modules/ npm-debug.log* .env* !.env.example # Custom (order preserved) *.log !keep.log
The later !keep.log rule re-includes that name when its parent directory is traversable. Ignoring a path does not untrack a committed file or remove a secret from history; use Git’s index and credential-rotation procedures when appropriate.
Keep the references close
Primary documentation supports the technical details above. Check it alongside the behavior of your own runtime and deployment.
Open Gitignore files →