Dart .gitignore template
The Dart template ignores the package tool cache, build output and compiled JavaScript, and takes the library side of the pubspec.lock argument by default.
At a glance
- Category
- Language
- Patterns in this template
- 9 rules
- Directories ignored
- 3 of the 9 rules end in a slash, so they match directories only
- Also needs an OS template
- Yes. Dart itself is tidy, so the remaining noise is from the editor and the file manager.
- Typical companions
- Flutter if this is an app rather than a plain package, plus an editor template.
In detail
.dart_tool is where the package tool keeps its resolved package configuration, build caches and generated entrypoints. It contains absolute paths to the package cache in your home directory, so it is meaningless on any other machine, and it is rebuilt by a single pub get. The older .packages file did the same job in a flatter format and is kept in the list for repositories that predate the change.
pubspec.lock is the decision to review. It pins the exact version of every direct and transitive dependency. For an application, that pinning is what makes a build reproducible, so most teams commit it and remove this line. For a package published to a registry, consumers resolve their own versions and the lockfile only describes what your own tests ran against, which is the case this template is written for.
The compiled JavaScript rules cover *.dart.js, *.js_, *.js.deps and *.js.map. These are what the web compiler produces from your Dart sources: the bundle itself, the dependency manifest and the source map. All four are regenerated on every build and none of them are readable enough to review in a diff.
doc/api is the generated API documentation directory. It is derived entirely from doc comments in the source, and committing it means every documentation change lands twice in the diff, once in the comment and once in the rendered HTML. Publishing it belongs to a release step rather than to the repository.
build is the general output directory, matched at any depth. In a workspace with several packages that catches each package's output, which is what you want, though it also means a source directory named build anywhere in the tree would be swallowed.
Examples
.dart_tool/
.packages
build/
pubspec.lock
doc/api/
*.dart.js
*.js_
*.js.deps
*.js.map9 lines exactly as the tool writes them, before any common additions you tick.
Things that catch people out
- pubspec.lock is ignored by default. Application projects should remove that line so deploys and CI resolve the same dependency versions the team tested.
- Ignoring .dart_tool wholesale also ignores package_config.json inside it, which is fine, but it means a clone cannot analyse the project until pub get has been run once.
- *.js.map is broad enough to catch source maps from an unrelated frontend build in the same repository.
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 →Flutter .gitignore template
The Flutter template adds generated plugin manifests and per platform build artefacts to the Dart rules, including the iOS pod directory and build modes.
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.
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.
Scala .gitignore template
What the Scala template ignores: the target output directory, the build server protocol folder, and the caches that Metals and Bloop keep inside the project.
R .gitignore template
The R template ignores saved workspaces, session history, rendered vignettes and check output, plus the .httr-oauth file that stores live access tokens.
Lua .gitignore template
A short template for a short toolchain: compiled bytecode from luac, packaged rock archives, and the local tree LuaRocks installs dependencies into.
Tools for this
- .gitignore Generator Generate .gitignore files for any project - 50+ templates for languages, frameworks, IDEs, and OS