Generate .gitattributes

Configure how Git handles files in your repository. Ensure consistent line endings and proper diffs across all operating systems.

Global Settings
? Base settings for all files in the repository.
Binary Files (Images, Media, Archives)
? Mark these as binary to prevent Git from modifying line endings.
Code & Text Files
? Ensure these are treated as text, with consistent line endings.
GitHub Linguist & Stats Unique
? Control how GitHub calculates language statistics for your repo.
Export Ignore Unique
? Files to exclude when using 'git archive' (e.g. downloading zip from GitHub).
Custom Rules

Preview

.gitattributes

About 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=auto by 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 (like binary or text) to each.
  • Step 3: Advanced Configuration - Use the "GitHub Linguist" section to refine your repo's stats. For example, mark .min.js files as "vendored" to exclude them from your language bar, or mark the docs/ 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 .gitignore or 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 .gitattributes file 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 involving git 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-vendored attribute to hide these files and show the true language breakdown of your work.
  • Standardize Editors: Combine this file with an .editorconfig file to ensure your code editor (VS Code, Sublime, etc.) respects the same rules as Git.

Frequently Asked Questions

What is the difference between text and binary in Git?
Text files (like code, HTML, Markdown) have lines that end in special characters. Git can normalize these to ensure consistency. Binary files (images, compiled executables) must be preserved exactly byte-for-byte. Marking a file as binary tells Git not to touch it.
What does 'text=auto' do?
The * 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.
How do I use the generated file?
Simply save the generated content into a file named .gitattributes (no extension) in the root folder of your Git repository. Commit and push it to share the settings with your team.
Can I exclude files from GitHub language stats?
Yes! Use the "GitHub Linguist & Stats" section in this tool. Checking "Ignore Minified JS" adds the linguist-vendored attribute, which tells GitHub to ignore those files when calculating the language breakdown bar.
Copied to clipboard!

 

Read Also: