Intermediate · 5 min read
.gitignore, for real
Patterns, exceptions, global ignore file, and why your file is still tracked.
The patterns
One pattern per line. A trailing / means a folder (build/). * matches anything except /, ** matches any depth (**/logs). A leading / anchors to the repository root (/config.json). Lines starting with # are comments.
Exceptions with !
!pattern re-includes a file: .env.* then !.env.example. Careful: you can't re-include a file if its parent folder is ignored; ignore folder/* instead of folder/.
Your personal ignore file
Editor and OS files (.DS_Store, .idea) belong in a global file, not in every project.
$ git config --global core.excludesFile ~/.gitignore_global
Already tracked? Untrack it
.gitignore never affects tracked files. Remove them from the index, keep them on disk, and use check-ignore to debug a rule.
$ git rm -r --cached dist$ git check-ignore -v dist/app.js