Control Line Endings With .gitattributes

Normalize CRLF/LF per file type so diffs stay clean across platforms.

macOSgitcliconfigLow risk
Add *.sh text eol=lf to .gitattributes to enforce LF for shell scripts.

01Command

Command
$ git config core.autocrlf input  # plus .gitattributes

02What it does

Line-ending drift causes noisy diffs and broken scripts; committing a .gitattributes file applies rules consistently for every clone, unlike local core.autocrlf settings that differ per machine. It is configuration as code.

03Risk

RiskLow risk
RequirementsGit 2.20+ (install with Homebrew or Xcode Command Line Tools)
CompatibilitymacOS with Git installed (Homebrew or Xcode Command Line Tools)
!Warning: Changing line-ending rules can produce a large one-time diff; coordinate with the team before converting a repository.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-10-13 · Category: Developer