Git configuration file defining path-specific settings for line endings, diff handling, merge strategies, and binary file detection.
.gitattributes
.gitattributes is a Git configuration file that assigns path-specific behavior to files in a repository. Placed at the repository root (or in any subdirectory), it tells Git how to treat matching paths — how to normalize line endings, which files are binary, how to generate diffs, and which merge strategies to apply. It is the mechanism that keeps a repository behaving consistently across every contributor’s operating system and editor.
- Line-ending normalization -
text=autoandeolsettings stop CRLF/LF churn from polluting diffs across Windows, macOS, and Linux. - Binary handling - Marking paths
binaryprevents Git from attempting line-based diffs and merges on assets like images or compiled files. - Custom diff and merge drivers - Attributes can route specific file types through language-aware diff or bespoke merge logic.
- Export and filtering rules -
export-ignoreand clean/smudge filters shape what ends up in archives and working trees.
In API operations, a repository is increasingly the source of truth for OpenAPI definitions, schemas, and GitOps configuration, and .gitattributes is what keeps those machine-read artifacts byte-stable. Consistent line endings and predictable diffs matter when governance tooling compares spec versions or when a pipeline validates a contract on every commit — noise introduced by an unmanaged working tree becomes false-positive drift. It works alongside .gitignore as the quiet plumbing that makes a repository a reliable, auditable record.