How to configure Git line endings
Configuring line endings properly prevents issues when collaborating across Windows, macOS, and Linux platforms in Git repositories.
As the creator of CoreUI with over 25 years of development experience, I’ve managed cross-platform teams and repositories for decades.
The most effective solution is to configure core.autocrlf and use a .gitattributes file to normalize line endings.
This approach ensures consistent line endings regardless of the operating system developers use.
Configure Git line endings using core.autocrlf and .gitattributes.
# On Windows
git config --global core.autocrlf true
# On macOS/Linux
git config --global core.autocrlf input
# Check current setting
git config core.autocrlf
# .gitattributes file in repository root
* text=auto
# Force LF for specific files
*.sh text eol=lf
*.bash text eol=lf
# Force CRLF for Windows scripts
*.bat text eol=crlf
*.cmd text eol=crlf
# Binary files
*.png binary
*.jpg binary
On Windows, core.autocrlf true converts LF to CRLF on checkout and CRLF to LF on commit. On Unix systems, input converts CRLF to LF on commit but doesn’t modify checkouts. The .gitattributes file provides repository-level control, overriding user settings. The text=auto directive lets Git automatically detect text files and normalize their line endings. Specific rules can enforce LF or CRLF for particular file types.
Best Practice Note
This is the same line ending configuration we use for CoreUI cross-platform development teams. Always commit the .gitattributes file to your repository to ensure consistent behavior for all contributors. After adding .gitattributes, run git add --renormalize . to apply the new settings to existing files.



