The .gitattributes file is used to define attributes for paths in your Git repository. It controls how files behave during Git operations such as merging, diffing, and checking out.
The file contains path patterns followed by attribute rules.
# Normalize line endings for all text files
* text=auto
# Markdown files with custom diff
*.md text diff=markdown
# Treat images as binary
*.jpg binary
Git automatically converts line endings and avoids merging or diffing binary files, ensuring consistent behavior across platforms.
# Automatically normalize line endings
* text=auto
# Mark image files as binary
*.png binary
*.jpg binary
# Prevent automatic merge for PNG files
*.png merge=binary
# Use markdown diff driver
*.md diff=markdown
# Apply rules only inside docs directory
docs/* text=auto
.gitattributes early in the project to avoid line-ending conflicts later.text=auto to keep repositories cross-platform friendly.git check-attr to verify behavior..gitattributes file and define rules for text and binary files.