Next.js .gitignore Template
The full, current Next.js .gitignore template — copy it as-is, or head to the .gitignore Generator to merge it with other stacks into one file.
Template
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. # dependencies /node_modules /.pnp .pnp.* .yarn/* !.yarn/patches !.yarn/plugins !.yarn/releases !.yarn/versions # testing /coverage # next.js /.next/ /out/ # production /build # misc .DS_Store *.pem # debug npm-debug.log* yarn-debug.log* yarn-error.log* # env files (can opt-in for committing if needed) .env* # vercel .vercel # typescript *.tsbuildinfo next-env.d.ts
What each entry does
Why every line in this template is excluded, not just what it matches.
| Entry | Why it's excluded |
|---|---|
| /node_modules | Installed npm/yarn/pnpm packages — fully reproducible from package.json and the lockfile, and can run into the tens of thousands of files. |
| /.pnp | Files matching /.pnp — a generated or machine-specific file type for this stack, safe to regenerate rather than track. |
| .pnp.* | Files matching .pnp.* — a generated or machine-specific file type for this stack, safe to regenerate rather than track. |
| .yarn/* | Excludes .yarn/* — generated or machine-specific for this stack, not something to track in version control. |
| !.yarn/patches | Re-includes .yarn/patches — carves out an exception to a broader exclusion pattern above it. |
| !.yarn/plugins | Re-includes .yarn/plugins — carves out an exception to a broader exclusion pattern above it. |
| !.yarn/releases | Re-includes .yarn/releases — carves out an exception to a broader exclusion pattern above it. |
| !.yarn/versions | Re-includes .yarn/versions — carves out an exception to a broader exclusion pattern above it. |
| /coverage | Test-coverage report output — regenerated by the test runner, not something to diff in git. |
| /.next/ | A generated/local directory (.next) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff. |
| /out/ | A generated/local directory (out) — excluded because its contents are either build output or machine-specific state, not source you'd want to review in a diff. |
| /build | Compiled/bundled output directory produced by the build tool — derived entirely from source, not source itself. |
| .DS_Store | macOS Finder's per-folder metadata file (icon positions, view settings) — pure OS clutter with no project value. |
| *.pem | Files matching *.pem — a generated or machine-specific file type for this stack, safe to regenerate rather than track. |
| npm-debug.log* | Files matching npm-debug.log* — a generated or machine-specific file type for this stack, safe to regenerate rather than track. |
| yarn-debug.log* | Files matching yarn-debug.log* — a generated or machine-specific file type for this stack, safe to regenerate rather than track. |
| yarn-error.log* | Files matching yarn-error.log* — a generated or machine-specific file type for this stack, safe to regenerate rather than track. |
| .env* | Files matching .env* — a generated or machine-specific file type for this stack, safe to regenerate rather than track. |
| .vercel | Files matching .vercel — a generated or machine-specific file type for this stack, safe to regenerate rather than track. |
| *.tsbuildinfo | Files matching *.tsbuildinfo — a generated or machine-specific file type for this stack, safe to regenerate rather than track. |
| next-env.d.ts | Files matching next-env.d.ts — a generated or machine-specific file type for this stack, safe to regenerate rather than track. |