How does Git handle line-ending normalization, and what do core.autocrlf and .gitattributes settings do?

Last updated 6 July 2026

  • Git can store text files with LF in the repo and convert line endings on checkout/commit. This avoids spurious diffs between Windows (CRLF) and Unix (LF) users.

  • core.autocrlf is a per-machine setting: true converts both ways (Windows), input converts to LF only on commit (Mac/Linux), false does nothing.

  • .gitattributes is committed and overrides machine settings, so the whole team behaves consistently (e.g. * text=auto, *.png binary). It is the preferred approach.

  • https://docs.github.com/articles/dealing-with-line-endings
  • https://dev.to/kevinshu/git-and-normalization-of-line-endings-228j
  • https://medium.com/towardsdev/line-endings-in-git-54d7f91e0daf
  • https://dipakp-docs.readthedocs.io/git-knowledge/git-line-endings/index.html
  • https://git-scm.com/docs/gitattributes
  • https://mirrors.edge.kernel.org/pub/software/scm/git/docs/gitattributes.html
  • https://community.br-automation.com/t/git-line-ending-configuration/4073
  • https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration
All Git interview questions