.gitignore — what not to track
Keep secrets and auto-generated files out of git
⏱ Est. ~6 min
01 · Read
Not everything in your project should be tracked by git. Two kinds of files always belong outside: auto-generated files like node_modules/ — these can be rebuilt with a single command (npm install). They're huge, constantly changing, and would bloat your repo.
Secret files like .env — these contain passwords, API keys, and other sensitive data. If you commit them to git and push to GitHub, anyone can see your secrets.
A .gitignore file tells git: "Pretend these files don't exist. Don't track them, don't commit them, don't even mention them."
Key points
- node_modules/ is generated — exclude it from git
- .env files contain secrets — never commit them
- .gitignore tells git which files to ignore
- It's one of the first files you create in any project
02 · Real-machine exercise
Create a .gitignore file with node_modules/ on the first line. The > operator creates the file (or overwrites it if it already exists).
echo "node_modules/" > .gitignore
03 · Real-machine exercise
Now add .env to the ignore list. The >> operator appends to the file, instead of overwriting — an important difference!
echo ".env" >> .gitignore
04 · Quiz
Why should node_modules not be committed to git?
- It's a secret file
- Git can't track it
- It's huge and can be rebuilt from package.json
- It contains passwords
05 · Fill in the blank
The file that tells git which files to ignore is called _____.
06 · Checklist
Confirm your .gitignore is set up right. You can run cat .gitignore to see the contents.
- node_modules/ is in .gitignore
- .env is in .gitignore
- You understand why these files shouldn't be committed
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.