Interview Q&A / Git & GitHub

BeginnerQuick answer1 min readUpdated 3 Oct 2026

What kinds of files should you put in .gitignore?

SHORT ANSWER

Generated, secret or machine-specific files: dependencies like node_modules, build output, logs, .env files, and editor or OS clutter. Source code and configuration the team needs must stay tracked.

Explain it simply

Ask of each file: can anyone rebuild it, or is it private to me? If so, it does not belong in the repository.

Dependencies come back through npm install. Build folders like dist/ come back from the build. Logs, caches and coverage reports are noise. .env files carry passwords and API keys, which must never be committed. Editor files like .vscode/ depend on taste. Commit a .env.example with fake values so teammates know what to set. Lock files such as package-lock.json should be committed.

Example

text
node_modules/
dist/
coverage/
*.log
.env
!.env.example

What to say in the interview

"I ignore anything generated, secret or personal: dependencies, build output, logs, .env files and editor files. I keep lock files and an .env.example committed. Anything the project needs to run from source stays tracked."

Common mistakes

  • Ignoring package-lock.json.

#git#gitignore#best-practice

Related questions

Practise more Git & GitHub questions

Test your recall with short answers, then return to the detailed explanations when you need context.

Open Git & GitHub quick answers →

Get new questions like this by email

One short email when something new and useful lands. No spam, unsubscribe in one tap.

By subscribing you agree to the Privacy Policy.