Ignoring Build Output Directories in Git

Ignore compiled and build output directories in git. Covers dist/, build/, out/, target/, and framework-specific build artifacts across all languages.

Pattern

Detailed Explanation

Build output directories contain compiled, bundled, or generated files that are fully reproducible from source code. Committing them wastes repository space, creates enormous diffs, and often causes merge conflicts that are impossible to resolve manually.

Common build output directories by ecosystem:

Directory Used By
dist/ Vite, Rollup, TypeScript, Angular, Python setuptools
build/ Create React App, Gradle, Go, many generic projects
out/ Next.js static export, IntelliJ IDEA, TypeScript
target/ Maven, Rust (Cargo), Scala (sbt)
bin/ .NET, Eclipse, Go
obj/ .NET, C#
.next/ Next.js server and client build cache
.nuxt/ Nuxt.js
_site/ Jekyll, Eleventy

Why build output should not be committed:

  1. Size — Bundled JavaScript, compiled JARs, or linked binaries can be orders of magnitude larger than the source code that generated them.
  2. Reproducibility — Every CI/CD pipeline rebuilds from source. Committed build output creates a false sense of "deploy from git" that breaks when the committed artifacts are stale.
  3. Merge conflicts — Minified bundles with hashed filenames change on every build. Two developers building from different branches will generate conflicting output that cannot be manually merged.
  4. Security — Source maps in build output can expose original source code. Build artifacts may embed secrets that were in environment variables during the build process.

Best practices:

  • Use a CI/CD pipeline (GitHub Actions, GitLab CI, Jenkins) to build and deploy artifacts.
  • Store release artifacts in a dedicated artifact repository (npm registry, Docker registry, Maven Central, S3).
  • If you must distribute built files (e.g., an npm package), use the files field in package.json to control what gets published, separate from what gets committed.

Catching everything: Add both the directory name and a wildcard pattern: dist/ ignores the directory, while **/dist/ catches nested occurrences in monorepos.

Use Case

A monorepo team using Turborepo finds that committed build artifacts from one package are causing CI cache invalidation across all packages in their pipeline.

Try It — .gitignore Generator

Open full tool