Mark Auto-Generated Files with linguist-generated
Configure .gitattributes to mark auto-generated files as linguist-generated, hiding them from GitHub pull request reviews and language statistics.
Detailed Explanation
Linguist-Generated Attribute
Auto-generated files — compiled protobuf code, GraphQL types, ORM migrations, minified bundles — are committed to the repository but shouldn't clutter pull request reviews or skew language statistics. The linguist-generated attribute addresses both concerns.
The Attribute
# Build output
dist/** linguist-generated
build/** linguist-generated
out/** linguist-generated
# Generated types
*.generated.ts linguist-generated
*.generated.go linguist-generated
*.pb.go linguist-generated
*.pb.ts linguist-generated
*_generated.py linguist-generated
# GraphQL codegen
src/__generated__/** linguist-generated
*.graphql.ts linguist-generated
# ORM generated
prisma/generated/** linguist-generated
*.dbml.go linguist-generated
# Minified
*.min.js linguist-generated
*.min.css linguist-generated
*.bundle.js linguist-generated
Effects on GitHub
| Feature | Default | With linguist-generated |
|---|---|---|
| Language statistics | Counted | Excluded |
| PR diff view | Expanded | Collapsed with "generated" label |
| Code search | Indexed | Excluded from search results |
| Code review | Reviewable | Hidden by default |
linguist-generated vs -diff
These are complementary attributes with different scopes:
| Attribute | Scope | Effect |
|---|---|---|
linguist-generated |
GitHub web UI | Collapses in PRs, excludes from stats |
-diff |
Git CLI | Suppresses git diff output |
For the best experience, combine both:
*.pb.go text -diff linguist-generated
Protobuf / gRPC Example
A common pattern in Go and TypeScript projects is committing generated protobuf code:
# Generated protobuf (Go)
*.pb.go text -diff linguist-generated
*_grpc.pb.go text -diff linguist-generated
# Generated protobuf (TypeScript)
*.pb.ts text -diff linguist-generated
*_grpc_pb.ts text -diff linguist-generated
This keeps the generated code in version control (for reproducible builds) while hiding it from reviews and statistics.
Use Case
Projects that commit auto-generated code (protobuf, GraphQL codegen, ORM migrations, build artifacts) should mark those files as linguist-generated. This is especially valuable for monorepos where generated code can dominate the repository's apparent language distribution.