0
0
GitHow-ToBeginner · 3 min read

How to Set autocrlf in Git: Simple Guide

Set autocrlf in Git using git config --global core.autocrlf true to automatically convert line endings. Use true on Windows to convert LF to CRLF on checkout and CRLF to LF on commit, input on Unix/Linux/macOS to convert CRLF to LF on commit only, or false to disable conversion.
📐

Syntax

The autocrlf setting controls how Git handles line endings between Windows (CRLF) and Unix/Linux (LF) systems.

Use the command below to set it:

  • git config [--global] core.autocrlf [true|input|false]

Explanation:

  • --global: Applies setting for the current user globally.
  • core.autocrlf: The setting name.
  • true: Converts LF to CRLF on checkout, CRLF to LF on commit (best for Windows).
  • input: Converts CRLF to LF on commit only (best for Unix/Linux/macOS).
  • false: Disables any conversion.
bash
git config --global core.autocrlf true
💻

Example

This example shows how to set autocrlf to true globally on Windows. It ensures files checked out have CRLF line endings and commits convert them back to LF.

bash
git config --global core.autocrlf true
git config --global --get core.autocrlf
Output
true
⚠️

Common Pitfalls

Common mistakes include:

  • Setting autocrlf incorrectly for your OS, causing unwanted line ending changes.
  • Mixing settings in global and local configs, leading to confusion.
  • Not normalizing line endings before changing autocrlf, causing many files to appear changed.

Always check your OS and project needs before setting autocrlf.

bash
git config --global core.autocrlf false  # disables conversion
# Wrong for Windows if you want CRLF on checkout

git config --global core.autocrlf true   # correct for Windows
📊

Quick Reference

ValueBehaviorRecommended For
trueConvert LF to CRLF on checkout, CRLF to LF on commitWindows users
inputConvert CRLF to LF on commit onlyUnix/Linux/macOS users
falseNo conversionProjects with mixed or custom line endings

Key Takeaways

Set core.autocrlf to true on Windows to handle line endings automatically.
Use core.autocrlf input on Unix/Linux/macOS to convert line endings on commit only.
Avoid mixing global and local autocrlf settings to prevent confusion.
Normalize line endings before changing autocrlf to avoid large diffs.
Disabling autocrlf is useful for projects with custom or mixed line endings.