Track the project, not installed dependencies.
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/Normally commit package.json and the chosen package-manager lockfile according to the project policy. Ignoring every JSON file would hide useful configuration.
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.
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-filesShould all JSON files be ignored?
Choose an answer.
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.