Flash cards
Review the key moves
What is the main idea behind Git .gitattributes?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
Which statement best captures the main point of this lesson?
Complete the missing token from the example code.
*.___ text eol=lfPut the learning moves in the order that makes the concept easiest to apply.
What is .gitattributes ?
The .gitattributes file is a special file that tells Git how to handle specific files in your repository.
It controls things like line endings, file types, merge behavior, custom diff tools, and more.
Everyone on your team gets the same settings because this file is versioned with your project.
For more about Git LFS, see the dedicated page .
When to Use .gitattributes
- To enforce consistent line endings across different operating systems
- To mark files as binary (so Git doesn't try to merge or change them)
- To enable Git LFS for large files
- To set up custom diff or merge tools for special file types
- To control how files are exported in archives
Create or Edit .gitattributes
- Go to the root of your repository (or a subfolder for local rules).
- Create or edit the .gitattributes file.
- Add rules, one per line, for how Git should treat files.
Example: Force Unix Line Endings for All Text Files
*.txt text eol=lfHandle Line Endings
Standardize line endings to avoid merge conflicts and broken files across different OSes.
Example: Set LF for Shell Scripts
*.sh text eol=lfMark Files as Binary
Tell Git which files are binary (not text).
This prevents Git from trying to merge or change line endings for these files.
Example: Mark PNG Files as Binary
*.png binaryEnable LFS for File Types
Use Git LFS for large files like images or datasets.
This tells Git to use LFS for these files:
Example: Track PSD Files with LFS
*.psd filter=lfs diff=lfs merge=lfs -textCustom Diff Settings
Tell Git to use a special tool to compare certain file types (like Markdown or Jupyter notebooks):
Example: Custom Diff for Markdown
*.md diff=markdownCheck Attributes
See what attributes are set for a file:
Example: Check Attributes of a File
git check-attr --all README.mdAdvanced Usage
- Merge Strategies: Set custom merge drivers for tricky files (like lock files or notebooks).
- Export-ignore: Exclude files from tar/zip archives created by git archive :
Example: Ignore Files on Export
docs/* export-ignoreTips & Best Practices
- Patterns work like .gitignore (wildcards, etc).
- Put .gitattributes in subfolders for rules that only apply there.
- Changing .gitattributes won't retroactively fix files already committed-re-add files to update them.
- Use git check-attr to debug attribute issues.
Note
.gitattributes is versioned with your project, so everyone on your team gets the same settings.