Next.js .gitignore template
The Next.js template ignores the framework build directory, the static export output, deployment metadata and the whole local environment file family with one wildcard.
At a glance
- Category
- Framework
- Patterns in this template
- 11 rules
- Directories ignored
- 4 of the 11 rules end in a slash, so they match directories only
- Also needs an OS template
- Yes. Nothing here covers the operating system or the editor.
- Typical companions
- npm, Yarn or pnpm, plus an OS template and an editor template.
In detail
.next is the build directory and the most important rule here. It holds the compiled server and client bundles, the route manifests, the image optimisation cache and the incremental build trace. It is regenerated by a build and it is large, and because much of it is content hashed, a committed copy produces a diff of thousands of renamed files on every change.
out is the static export directory, produced only when the project exports to plain HTML files. Having both rules means the template covers either output mode without you needing to know which one this project uses. build appears too, for projects that redirect output there.
.env*.local is a single wildcard doing the work of four separate rules. It matches .env.local, .env.development.local, .env.production.local and .env.test.local in one line. The deliberate omission is the same as in the sibling template: a plain .env is not matched, because that file is meant to hold shared non secret defaults that everyone gets from the repository.
.vercel holds deployment linkage: the project and organisation identifiers that connect this checkout to a hosted project. It is created by the deployment tool on your machine and describes your account's relationship to the project, not the project itself. Committing it points every collaborator at the same hosted project, which is occasionally what a team wants and more often an accident nobody notices until a deploy goes somewhere unexpected.
next-env.d.ts is the odd one out, and the guidance has shifted. The file is regenerated on every build, so ignoring it is defensible, but the framework's own scaffolding commits it, because a fresh clone that runs a type check before a build otherwise fails on missing global types. If your CI type checks before building, remove that line.
Examples
.next/
out/
build/
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.env*.local
.vercel
*.tsbuildinfo
next-env.d.ts11 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- The plain .env is not covered. Only the .local variants match the wildcard, so a secret placed in .env will be committed.
- Ignoring next-env.d.ts breaks a type check that runs before the first build in a fresh clone, because the file has not been generated yet.
- *.tsbuildinfo is ignored here, which is correct, but adding it after the file was committed needs git rm --cached before git stops tracking it.
Try it: .gitignore Generator
Pick one or more templates, tick the common additions you want, and copy or download the combined .gitignore.
.gitignore Generator
LOCAL · Browser-OnlyGenerate comprehensive .gitignore files by combining templates for languages, frameworks, IDEs, and operating systems
Language
Framework
IDE
OS
Build Tool
Infrastructure
Common Additions
Preview
Select templates or common additions to generate a .gitignore file.
Related .gitignore templates
All .gitignore templates →React .gitignore template
A short template built around one idea: the .env.local family is per developer and never committed, while the plain .env is shared and usually should be.
TypeScript .gitignore template
The TypeScript template ignores compiled output, source maps and build info, but its *.d.ts rule is broader than most projects want. Here is each line.
Node.js .gitignore template
The longest JavaScript oriented template: dependency directories, every package manager's debug log, bundler caches, env files and Yarn Plug'n'Play state.
Vue .gitignore template
The Vue template ignores build output and local environment files, and is one of the few that also carries operating system and editor rules of its own.
Angular .gitignore template
The Angular template ignores compiled output, the type checker's intermediate folder, the local build cache, and logs older test tooling leaves behind.
Django .gitignore template
The Django template adds four framework rules to the usual Python ones: local settings, the SQLite database, uploaded media and collected static files.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS
- .env Editor & Validator Edit and validate .env files online - detect duplicates, mask secrets, generate .env.example