TypeScript .gitignore template
The TypeScript template covers compiler output, incremental build state and source maps, and takes an aggressive line on declaration files that many projects need to soften.
At a glance
- Category
- Language
- Patterns in this template
- 10 rules
- Directories ignored
- 3 of the 10 rules end in a slash, so they match directories only
- Re-include rules
- 2 lines start with ! to keep something back
- Also needs an OS template
- Yes. Editor and operating system noise are handled by separate templates.
- Typical companions
- Node.js or a framework template, plus npm, Yarn or pnpm.
In detail
The compiler writes JavaScript, declaration files and source maps next to or beside your TypeScript sources. Everything the compiler emits is reproducible from the sources plus the compiler configuration, so it belongs outside version control. dist and build are the two output directory names the template assumes, matched at any depth because neither rule is anchored.
The two tsbuildinfo rules cover incremental compilation state. That file records the fingerprint of every input from the previous run so the next build can skip unchanged files. It refers to absolute paths on the machine that produced it, which makes a committed one useless at best and a cause of confusing stale builds at worst.
The *.d.ts rule is the one to look at carefully. It ignores every declaration file in the repository, not only generated ones. A project with a hand written types/global.d.ts, an ambient module declaration, or a framework generated file it deliberately tracks will find those files silently untracked. The two negation lines only bring back the .d.cts and .d.mts variants, which is unlikely to be what you needed.
The usual fix is to keep the rule but anchor it to the output directory, or to drop it entirely and rely on dist and build. Since the compiler already writes declarations into the output folder, ignoring that folder covers the generated case without touching anything you wrote by hand.
*.js.map matches source maps in the working tree. Whether you want those published alongside a release is a separate decision from whether they belong in the repository, and this rule only speaks to the second question. Most projects generate them during the build and upload them to an error tracking service instead, which keeps stack traces readable without putting the files in git.
Examples
node_modules/
*.js.map
*.d.ts
!*.d.cts
!*.d.mts
dist/
build/
.tsbuildinfo
*.tsbuildinfo
.eslintcache10 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- *.d.ts is not scoped to the output folder. If you keep a hand written declaration file anywhere in the repository, add a negation for it or narrow the rule, otherwise it disappears from git status and nobody notices until a clean clone fails to compile.
- Both dist/ and build/ are matched at any depth. In a monorepo that catches every package's output, which is usually right, but it also catches a source directory that happens to be called build.
- Adding *.tsbuildinfo after the file has already been committed changes nothing on its own. Git keeps tracking files it already knows about, so you need git rm --cached on the file first.
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 →JavaScript .gitignore template
Every rule in the JavaScript .gitignore template explained: why node_modules is restored rather than committed, and what the old package folders catch.
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.
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.
Python .gitignore template
A line by line read of the Python .gitignore template: bytecode caches, virtual environments, packaging output, test caches and the lib/ rule that bites.
Java .gitignore template
What the Java .gitignore template ignores: compiled classes, packaged archives, crash dumps, and the negations that keep the Gradle wrapper jar tracked.
Go .gitignore template
The Go template ignores platform binaries by extension, which misses the extensionless binary go build produces on Linux and macOS. Here is what to add.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS
- package.json Generator Generate package.json files with a form-based builder - 8 project presets, all fields supported