How the .gitattributes File Can Be a Game-Changer for Your Version Control
Git Attribute Files Guide
Photo by Yancy Min on Unsplash
How the .gitattributes File Can Be a Game-Changer for Your Version Control
Guide to Using a Git Attribute File
1. Handling Line Endings:
Different operating systems have different line endings. Windows uses Carriage Return Line Feed (CRLF), while macOS and Linux use just Line Feed (LF). The .gitattributes file can help normalize these line endings so that they remain consistent regardless of the operating system.
# Ensure LF line endings even on Windows
*.txt text eol=lf
2. Marking Files as Binary:
Some files, like images, should be treated as binary to prevent Git from trying to merge or display differences as if they were text.
*.png binary
3. Export-Ignore:
When creating an archive (e.g., zip or tarball) of your repository, you might not want to include certain files. The export-ignore attribute lets you exclude files or paths.
.gitignore export-ignore
README.md export-ignore
4. Merge Strategy:
For some files or file types, you might want to specify a custom merge strategy or even prevent them from being merged.
# Use the "ours" merge strategy for the config file
config.yml merge=ours
5. Setting File Locking:
In workflows where locking is necessary, like with Git LFS (Large File Storage), you can use .gitattributes to specify which files need to be locked by default.
*.psd lockable
6. Filtering Content:
You can define custom filters to be applied when checking files into or out of the repository. This can be useful for tasks like secret scrubbing.
*.properties filter=secretClean 메타데이터
- post_id
- 8e31e1eacf13
- slug
- how-the-gitattributes-file-can-be-a-game-changer-for-your-version-control-8e31e1eacf13
- url
- https://medium.com/@hanancs/how-the-gitattributes-file-can-be-a-game-changer-for-your-version-control-8e31e1eacf13
- canonical_url
- https://medium.com/@hanancs/how-the-gitattributes-file-can-be-a-game-changer-for-your-version-control-8e31e1eacf13
- author_url
- https://medium.com/@hanancs
- status
- ok
- fetched_at
- 2026-07-11 09:34:02