github/gitignore · Nextjs.gitignore
Next.js .gitignore Template Explained
Why Nextjs.gitignore ignores .next, out, node_modules, .env files, .vercel, next-env.d.ts and *.pem, and how it differs from the Node template.
Nextjs.gitignore has almost the same contents as the .gitignore created by create-next-app. Most rules start with / and are anchored to the repository root, so if your app lives in a subfolder of a monorepo, adjust the paths or use the Node template as well.
Next.js reads several environment files, including .env, .env.local and .env.development.local. This template excludes both .env and .env*.local.
Rules explained
| Pattern | What it ignores and why |
|---|---|
/.next//out//build | Next.js buildThe output and cache of next build (.next) and static export output (out). They are recreated during deployment. |
/node_modules/.pnp.pnp.js | DependenciesPackage install output and Yarn Plug'n'Play files. They are anchored to the root only, so node_modules in sub-packages is not blocked. |
.env.env*.local | Environment variablesEnvironment files containing secret values. Variables starting with NEXT_PUBLIC_ are embedded in the build output and exposed to the browser, so use secrets only on the server without that prefix. |
.vercelnext-env.d.ts*.tsbuildinfo | Deployment and generated type filesProject link information created by vercel link, the type declaration file Next.js regenerates during development and builds, and TypeScript incremental build information. |
*.pem | CertificatesCertificate and private key (.pem) files used for local HTTPS development or integrating with external services. Do not commit private keys. |
npm-debug.log*yarn-debug.log*yarn-error.log*/coverage.DS_Store | Logs and otherPackage manager logs, test coverage and macOS Finder files. |
Practical notes
- In a monorepo (
apps/web), root-anchored rules such as/node_modulesdo not apply to sub-apps. Selecting the Node template as well catchesnode_modules/at any depth. - Commit configuration and lockfiles such as
next.config.jsandpackage-lock.json. - Instead of committing
.env, share the names of the required variables in the README or.env.example.
Original template
Nextjs.gitignore
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.# dependencies/node_modules/.pnp.pnp.js# testing/coverage# next.js/.next//out/# production/build# misc.DS_Store*.pem# debugnpm-debug.log*yarn-debug.log*yarn-error.log*# local env files.env*.local.env# vercel.vercel# typescript*.tsbuildinfonext-env.d.ts
Templates from github/gitignore/Nextjs.gitignore @356fd7b (2026-09-11) · CC0-1.0