How to Standardize Line Endings in Git Without Committing `.gitattributes`
When developing with Git, differences between CRLF and LF can become an issue when working across Windows and Linux/macOS. A common solution is to place a .gitattributes file in the repository to define line-ending rules. However, there are also cases where you may want to: Avoid adding .gitattributes to the repository Standardize line endings only in your own environment Apply the same rules…
When developing with Git, inconsistencies between CRLF and LF line endings can cause issues when collaborating across Windows and Linux/macOS systems. Instead of adding .gitattributes to every repository, you can configure line ending rules without committing the file.
For specific repositories, create a .git/info/attributes file and define the rules, such as:
* text=auto eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf
This configuration treats regular text files as LF and Windows batch files (.bat, .cmd) as CRLF.
To apply common settings across all Git repositories, configure the global attribute file location:
git config --global core.attributesFile ~/.gitattributes
Then, create a file at ~/.gitattributes with similar rules:
* text=auto eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf
Choose the appropriate method based on your needs: use .git/info/attributes for specific repositories, or the global configuration for an entire Git environment. If required, use .git/info/attributes for exceptional rules in a specific repository.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.