Generate .gitattributes
Configure how Git handles files in your repository. Ensure consistent line endings and proper diffs across all operating systems.
Preview
.gitattributesAbout the Gitattributes Generator
The Gitattributes Generator Online is a comprehensive, free utility designed to streamline the configuration of Git repositories for developers worldwide. A .gitattributes file is a critical component of any professional software project, yet it is often overlooked. It serves as the rulebook for how Git interacts with the files in your project, ensuring consistency across different operating systems (Windows, macOS, Linux) and development environments.
Whether you are a solo developer or part of a large enterprise team, inconsistent line endings (CRLF vs. LF) can cause unnecessary merge conflicts and "phantom" diffs that clutter your commit history. This tool solves that problem instantly by generating a standardized configuration file. It also empowers you to manage binary files correctly, preventing Git from corrupting images or PDFs during checkouts, and gives you granular control over how GitHub analyzes your repository's language composition.
How to Use This Tool
Creating your perfect configuration is simple and takes less than a minute:
- Step 1: Global Settings - We've enabled
* text=autoby default. This is the industry standard, instructing Git to automatically handle line ending normalization for text files while leaving binary files untouched. - Step 2: Select File Types - Navigate through the "Binary Files" and "Code & Text" sections. Check the boxes for the file extensions used in your project (e.g.,
.png,.js,.py). The tool automatically applies the correct attributes (likebinaryortext) to each. - Step 3: Advanced Configuration - Use the "GitHub Linguist" section to refine your repo's stats. For example, mark
.min.jsfiles as "vendored" to exclude them from your language bar, or mark thedocs/folder as "generated" to keep them out of diffs. - Step 4: Export Ignore - If you distribute your code via "Download ZIP" on GitHub, use the "Export Ignore" section to exclude development files like
.gitignoreor CI configs from the final archive. - Step 5: Generate & Download - Your file is built in real-time. Click "Copy to Clipboard" to paste it directly into your editor, or "Download .gitattributes" to save the file. You can also generate a unique permalink to share your configuration with teammates.
Why You Need a .gitattributes File
Git is smart, but it's not perfect. Without explicit instructions, it relies on heuristics to determine if a file is text or binary. This guessing game can lead to disastrous results, such as corrupted binary assets or massive diffs caused solely by line-ending differences between Windows (CRLF) and Unix (LF) systems.
By including a .gitattributes file, you enforce a "contract" that every developer's machine must follow. This ensures that a JPEG image is never treated as a text file, and that a shell script always retains LF line endings, regardless of whether it's checked out on Windows or Ubuntu. It is a small file that prevents big headaches, making it a best practice for every repository.
Tips for a Clean Repository
- Commit Early: Add your
.gitattributesfile in the very first commit of your repository. This prevents files from being committed with incorrect line endings that then need to be fixed later (which can be a painful process involvinggit renormalize). - Use Linguist Overrides: If your project uses a lot of 3rd-party libraries or generated code, your GitHub language bar might be misleading. Use the
linguist-vendoredattribute to hide these files and show the true language breakdown of your work. - Standardize Editors: Combine this file with an
.editorconfigfile to ensure your code editor (VS Code, Sublime, etc.) respects the same rules as Git.
Frequently Asked Questions
binary tells Git not to touch it.
* text=auto rule tells Git to detect whether a file is text or binary. If it's text, Git normalizes line endings to LF in the repository. When you checkout the file on Windows, it converts them to CRLF. On Mac/Linux, they stay as LF.
.gitattributes (no extension) in the root folder of your Git repository. Commit and push it to share the settings with your team.
linguist-vendored attribute, which tells GitHub to ignore those files when calculating the language breakdown bar.
Read Also: