React .gitignore template
The React template ignores build output and the local environment file family, drawing a deliberate line between shared configuration and per developer overrides.
At a glance
- Category
- Framework
- Patterns in this template
- 12 rules
- Directories ignored
- 4 of the 12 rules end in a slash, so they match directories only
- Also needs an OS template
- Yes. This template is small and covers nothing outside the project itself.
- Typical companions
- npm, Yarn or pnpm, plus an OS template and an editor template.
In detail
The interesting rules here are the four environment ones: .env.local, .env.development.local, .env.test.local and .env.production.local. The convention they encode is a two tier system. Files without the .local suffix hold shared defaults and are meant to be committed, while the .local variants hold whatever one developer needs to override on their own machine and are not.
That distinction is worth understanding rather than memorising, because it is the reason this template does not ignore .env at all. If you put a real secret in the plain .env expecting the template to protect it, nothing will stop the commit. Anything sensitive belongs in a .local file, or better, outside the repository entirely.
There is a second consideration specific to frontend work. Values that reach the browser bundle are not secret whatever file they came from, because anyone can read them in the shipped JavaScript. The environment rules here are about keeping one developer's local API endpoint out of everyone else's checkout, not about protecting a key that the build inlines anyway.
build and dist are the two output directory names, covering both the classic toolchain and the newer bundlers. Both are produced from tracked sources, both are large, and both change wholesale whenever a dependency version moves, which makes them the worst possible thing to have in a diff.
The rest is small: node_modules, the three debug logs, the coverage directory and .eslintcache. Together they make this a template you almost always combine with something else rather than use on its own. A real project wants a package manager template for the lockfile rules, an operating system template, and whichever editor template matches the team, which is three more selections before the output is complete.
Examples
node_modules/
build/
dist/
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*
coverage/
.eslintcache12 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- The plain .env is not ignored by this template. Add it yourself if your project keeps one, because the four rules here only cover the .local variants.
- Anything the bundler inlines into the browser bundle is public regardless of which file it came from. Ignoring a file does not make the value it held secret.
- coverage/ is unanchored, so a source directory named coverage anywhere in the tree would also be ignored.
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 →Next.js .gitignore template
What the Next.js template ignores: the build cache, the static export folder, deployment state, and one wildcard that covers every local environment file.
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.
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.
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.
Flask .gitignore template
The Flask template adds the instance folder to the usual Python rules, which is the framework's designated place for configuration that must not be committed.
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