Frequently Asked Question
How does .gitignore work, and what should it contain?
.gitignore is a plain-text file at the root of the repository (or in any
subdirectory) listing path patterns that Git should pretend do not exist. Files
matching those patterns are skipped by git add ., omitted from git status, and
generally invisible to Git. Typical entries: build artefacts (build/, *.o,
*.pyc, target/), package directories (node_modules/, .venv/), editor cruft
(*.swp, .vscode/, .idea/), OS noise (.DS_Store, Thumbs.db), and, most
importantly, anything containing secrets (.env, credentials.json, *.key).
Patterns use shell-glob syntax with a few extensions: a trailing / matches
directories only; a leading / anchors to the repository root; ** matches any
number of intermediate directories; !pattern un-ignores. The crucial caveat is
that .gitignore only affects untracked files, if you have already committed
something, adding it to .gitignore will not remove it from history, and git rm --cached file is needed to stop tracking it. Always write a .gitignore before
your first commit; GitHub maintains a useful collection of language-specific
templates at github.com/github/gitignore.