REFERENCE · GIT BASICS

Gitignore for Node

Track the project, not installed dependencies.

A starting point, not a universal rule

Ignore installed dependencies and local log files. Ignore build directories only when this repository does not intentionally version its build output. Some static-site repositories do.

node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Optional only when outputs are not intentionally tracked:
# dist/
# build/

Keep the reproducibility files

Normally commit package.json and the chosen package-manager lockfile according to the project policy. Ignoring every JSON file would hide useful configuration.

Local environment files

You may ignore local .env files when they hold machine-specific settings or secrets. Keep a safe example with placeholders if the team needs setup guidance. An ignore pattern does not remove a leaked secret from history.

Diagnose instead of guessing

Check the matching ignore rule and list tracked files. If node_modules is already tracked, review a deliberate index cleanup rather than assuming .gitignore changed history.

git check-ignore -v node_modules/
git ls-files

Quick check

Should all JSON files be ignored?

Choose an answer.

Sources and scope

Command blocks are syntax examples checked against official documentation, not fabricated terminal output. Replace uppercase placeholders with your actual names and inspect status before commands that change work.

gitignore · git-check-ignore · git-ls-files ·

All references · Course map

Git, Visually · Reference