Lesson 22 / 28
.gitignore
Keep build output, dependencies and secrets out of Git with .gitignore patterns.
By Rahul Agarwal · 15 years in web development · Updated 1 Oct 2026
Patterns to exclude
A .gitignore file at the repo root lists patterns Git should never stage — build output, dependencies, secrets.
node_modules/
dist/
.env
*.logAlready-tracked files ignore it
.gitignore only affects untracked files. If a file is already committed, remove it from tracking with git rm --cached <file> first.