React & Next.js .gitignore Template
Next.js generates a massive `.next` compilation directory, incremental cache chunks, and preview artifacts. This template is optimized for modern Next.js 13/14/15 App Router and Pages Router projects.
| 1 | # Dependencies |
| 2 | /node_modules |
| 3 | /.pnp |
| 4 | .pnp.js |
| 5 | |
| 6 | # Testing |
| 7 | /coverage |
| 8 | |
| 9 | # Next.js build output |
| 10 | /.next/ |
| 11 | /out/ |
| 12 | |
| 13 | # Production build |
| 14 | /build |
| 15 | |
| 16 | # Debug logs |
| 17 | npm-debug.log* |
| 18 | yarn-debug.log* |
| 19 | yarn-error.log* |
| 20 | |
| 21 | # Local environment secret files |
| 22 | .env*.local |
| 23 | .env |
| 24 | |
| 25 | # Vercel deployment artifacts |
| 26 | .vercel |
| 27 | |
| 28 | # TypeScript build info cache |
| 29 | *.tsbuildinfo |
| 30 | next-env.d.ts |
Key Rules & Why They Are Ignored
/.next/Internal compilation cache, server bundles, and route manifests created by Next.js.
.vercelLocal CLI deployment cache containing project IDs and team metadata.
.env*.localLocal overrides for environment secrets.
Already Committed Ignored Files? Purge from Git Cache
Adding a pattern to .gitignore does NOT delete files that were already tracked in previous commits. Run this command to remove them from tracking without deleting your local copies:
git rm -r --cached . && git add . && git commit -m "Untrack ignored files"Frequently Asked Questions About Next.js & React .gitignore
Frequently Asked Questions
Everything you need to know regarding specifications, syntax, and security best practices.
Next.js officially advises ignoring or committing `next-env.d.ts`. If ignored, Next.js will regenerate it automatically on `npm run dev` or `npm run build`.