Gitattributes Generator
Define text normalization, safe script EOL, binary patterns, Git LFS, and release archive rules.
-
1Enter data
Enter content, paste text or load a file from disk. -
2Click the button
The tool will immediately process your data in the browser. -
3Get the result
Copy the finished text or save the file to your device.
return "Result ready in 0.1s";
}
Rate this tool:
Related tools
Other tools you may find usefulGitattributes generator for consistent EOL, binary files, and Git LFS
Gitattributes Generator builds a repository file-handling policy for Git. It configures automatic text detection, a chosen line ending, safe overrides for POSIX and Windows scripts, a broad set of binary formats, optional Git LFS patterns, and paths excluded from git archive.
How Git interprets attributes
Each line combines a path pattern with attributes. The rule * text=auto eol=lf asks Git to detect text, normalize it in the index, and write LF in the working tree. The crlf alternative keeps normalized repository data while checking text out with CRLF. When automatic normalization is disabled, the generator truly omits the global rule instead of silently adding another text=auto.
| Rule | Meaning | Typical use |
|---|---|---|
text=auto | Detect and normalize text automatically | Source code, configuration, and documentation |
eol=lf | Write LF in the working tree | Shell, Linux, containers, and CI |
binary | Shortcut for -diff -merge -text | Images, fonts, archives, audio, and video |
filter=lfs | Apply Git LFS pointer filters | Large assets that must remain versioned |
export-ignore | Omit a path from an archive | Tests and repository-only configuration |
Line endings and executable scripts
A global choice must not break scripts. The generator therefore always adds *.sh, *.bash, and *.zsh text eol=lf. An interpreter reads the shebang from the first line; CRLF can leave an invisible \r in the interpreter path and fail with a “bad interpreter” error. Windows *.bat and *.cmd files explicitly receive eol=crlf.
An EOL attribute does not set executable permissions. The executable bit is a separate Git index property; on Unix, set it with chmod +x file.sh followed by git add file.sh. Repeat repository automation rules with the GitLab CI Generator.
Binary files without misleading diffs
The generated list covers common PNG, JPEG, GIF, WebP, AVIF, and ICO images, PDF documents, fonts, archives, media, and executable libraries. The binary macro disables text conversion and automatic merging. SVG is intentionally absent because it is text-based XML and a meaningful diff can be useful. JSON, YAML, and source files remain text as well.
Explicit patterns communicate intent better than heuristics alone, but they do not compress files or shrink history. Build artifacts that do not belong in the index should be excluded before commit with the Gitignore Generator. Optimize application images when possible instead of sending every asset to LFS by default.
Git LFS patterns and validation
When LFS is enabled, every nonempty line receives filter=lfs diff=lfs merge=lfs -text, and duplicate patterns are removed. The tool rejects control characters, whitespace, a leading !, a leading comment marker, trailing slashes, and lists above 50 entries. Those forms are ambiguous or do not behave in attributes as many users expect.
The attributes alone do not migrate existing history or install the extension. Every contributor and CI runner needs Git LFS, and the repository needs initialization. Before committing, inspect a path with git check-attr -a -- path and review git lfs track. Do not use LFS for mergeable files such as source code, manifests, or small SVG documents.
Deploying and renormalizing the repository
- Choose LF for projects deployed on Linux, or deliberately select CRLF for Windows-oriented working text.
- Keep
text=autounless the repository already has a detailed extension-by-extension policy. - Enable LFS only for specific large formats and remove patterns the project never stores.
- Save the output as
.gitattributesat the repository root, then rungit add --renormalize .. - Review the diff and commit normalization separately from logic changes so code review remains understandable.
Align editor behavior with the EditorConfig Generator, and repeat important consistency checks through the GitHub Actions Generator. EditorConfig influences how an editor saves a file; gitattributes controls how Git stores and checks it out. They complement each other.
Release archives with export-ignore
The archive option marks .github, tests, phpunit.xml, .gitignore, and .gitattributes with export-ignore. This affects only git archive. It does not remove files from the repository, a clone, or an archive made by a generic ZIP application. Verify a release with git archive HEAD | tar -tf - before publishing.
Frequently asked questions
Will existing line endings change immediately?
Not in the current index. Run git add --renormalize ., review the diff, and commit it. Future checkouts then follow the declared policy.
Do binary and Git LFS mean the same thing?
No. binary disables text behavior while content remains in ordinary Git objects. LFS replaces content with a small pointer and stores the data in a separate service.
Why do shell scripts always use LF?
CRLF can append a carriage return to the interpreter path in a shebang and prevent execution. An explicit LF override protects scripts even when global working-tree text uses CRLF.
Can I enter a directory as an LFS pattern?
A trailing slash does not work recursively in attributes. Use a file pattern such as assets/** or assets/**/*.psd, depending on what the repository actually needs.
Does .gitattributes replace .editorconfig?
No. Git normalizes data during add and checkout, while EditorConfig guides the editor during save. Align EOL settings in both files to avoid recurring local modifications.