How to fix warning: LF will be replaced by CRLF in file.txt. The file will have its original line endings in your working directory in Git

GitBEGINNERLOWUpdated Dec 6, 2025· 312 views

This Git warning appears on Windows when files have Unix-style line endings (LF) but Git is configured to convert them to Windows-style (CRLF). While not an error, this indicates a line ending configuration mismatch that can cause issues in cross-platform projects. Configure core.autocrlf appropriately or use .gitattributes for consistent handling.

Quick fix

Fixes warning: LF will be replaced by CRLF in file.txt. The file will have its original line endings in your working directory

git config --global core.autocrlf
  1. Understand what the warning means
  2. Choose the right configuration for your situation
  3. Create a .gitattributes file for project-level control
  4. Normalize line endings in existing repository
git — error
git config --global core.autocrlf
warning: LF will be replaced by CRLF in file.txt. The file will have its original line endings in your working directory

What this error means

The "LF will be replaced by CRLF" warning tells you that Git is automatically converting line endings in your files. This happens because: **LF (Line Feed, \n)** is the Unix/Linux/macOS line ending standard. **CRLF (Carriage Return + Line Feed, \r\n)** is the Windows line ending standard. When `core.autocrlf` is set to `true` (the default on Windows Git installations), Git performs automatic conversions: - **On checkout**: Converts LF to CRLF so files work correctly in Windows editors - **On commit**: Converts CRLF back to LF to keep LF in the repository This warning appears when you add or stage a file that has LF endings and Git is going to convert it to CRLF in your working directory. The message "The file will have its original line endings in your working directory" is somewhat confusing - it actually means the file you're committing will be stored with LF in the repository, while your local copy will be converted to CRLF. This is not an error, but a notification that automatic line ending conversion is happening. For many projects, especially those with developers on different operating systems, consistent line endings are important to avoid: - Merge conflicts caused purely by line ending differences - Diffs showing entire files as changed when only line endings differ - Build or script failures on systems expecting specific line endings

Typical symptoms

  • Warning appears when running 'git add' on Windows
  • Warning shows for files created on Linux/macOS or downloaded from the web
  • Multiple warnings appear when cloning repositories from Unix systems
  • Bash scripts or shell files show this warning
  • Warning appears after editing files in certain editors that use LF by default
  • CI/CD builds show line ending warnings or failures
  • Diff tools show entire files as changed with no visible content changes

Common causes

  1. core.autocrlf is set to 'true' and files have LF line endings
  2. Files were created on Unix/Linux/macOS and are being added on Windows
  3. Editor is configured to use LF line endings by default (VS Code, Sublime, etc.)
  4. Repository was cloned from a Unix-based system without .gitattributes
  5. Project lacks a .gitattributes file to standardize line endings
  6. Downloaded files from the internet often have LF endings
  7. Copy-pasting code from web sources may introduce LF endings
  8. Docker containers or WSL create files with LF on Windows filesystem

How to fix "warning: LF will be replaced by CRLF in file.txt. The file will have its original line endings in your working directory"

1Understand what the warning means

First, understand that this is a warning, not an error. Your files will still be committed correctly. The warning tells you:

1. The file currently has LF (Unix) line endings
2. Git will store it with LF in the repository (good for cross-platform)
3. Git will convert it to CRLF in your working directory (so Windows tools work)

Check your current autocrlf setting:

bash
git config --global core.autocrlf

Common values:
- true - Converts LF to CRLF on checkout, CRLF to LF on commit (Windows default)
- input - Converts CRLF to LF on commit only, no conversion on checkout
- false - No automatic conversion

To see which files trigger the warning:

bash
# Add files verbosely to see warnings
git add -v .
2Choose the right configuration for your situation

The best setting depends on your team and project:

Option 1: Keep autocrlf=true (Recommended for Windows-only teams)

bash
git config --global core.autocrlf true

- Files are CRLF locally, LF in repo
- The warning is expected - you can ignore it
- Windows tools work correctly

Option 2: Use autocrlf=input (Recommended for cross-platform teams)

bash
git config --global core.autocrlf input

- Files keep their endings locally
- Only converts CRLF to LF on commit
- Avoids the warning but you may have LF files locally

Option 3: Disable autocrlf=false (Not recommended)

bash
git config --global core.autocrlf false

- No automatic conversion
- Files stay exactly as they are
- Risk: CRLF might accidentally get committed to the repository

Which should you choose?
- Windows-only project: true is fine
- Cross-platform project: Use input or .gitattributes (see next step)
- Linux/macOS: input or false (CRLF rarely appears)

3Create a .gitattributes file for project-level control

The best practice for cross-platform projects is using a .gitattributes file in the repository root. This overrides individual user settings and ensures consistency.

Create a basic .gitattributes file:

bash
# Create the file in your repository root
touch .gitattributes

Add these contents for a typical project:

gitattributes
# Set default behavior to automatically normalize line endings
* text=auto

# Explicitly declare text files you want to be normalized
*.c text
*.h text
*.cpp text
*.hpp text
*.py text
*.js text
*.ts text
*.json text
*.xml text
*.yml text
*.yaml text
*.md text
*.txt text
*.css text
*.html text
*.sh text eol=lf
*.bash text eol=lf

# Declare files that should always have CRLF line endings on checkout
*.bat text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf

# Declare binary files that should not be modified
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.pdf binary
*.zip binary
*.gz binary
*.tar binary
*.exe binary
*.dll binary
*.so binary
*.dylib binary

Commit the .gitattributes file:

bash
git add .gitattributes
git commit -m "Add .gitattributes for consistent line endings"
4Normalize line endings in existing repository

If you've added a .gitattributes file to an existing repository, you should normalize all files to apply the new settings:

Step 1: Save your work

bash
git stash

Step 2: Remove all files from the index (not from disk)

bash
git rm --cached -r .

Step 3: Re-add all files (this applies .gitattributes)

bash
git reset --hard

Step 4: Add all files back

bash
git add .

Step 5: Check what changed

bash
git status
# You'll see files that had their line endings normalized

Step 6: Commit the normalized files

bash
git commit -m "Normalize line endings"

Step 7: Restore your stashed work

bash
git stash pop

This process rewrites files to match your .gitattributes rules.

5Configure your editor to use consistent line endings

Prevent future warnings by configuring your editor to match your project's conventions.

VS Code:
Add to your workspace or user settings (.vscode/settings.json or user settings):

json
{
  "files.eol": "\n"
}

Or use "\r\n" for CRLF if that's your standard.

Sublime Text:
Add to Preferences > Settings:

json
{
  "default_line_ending": "unix"
}

JetBrains IDEs (IntelliJ, PyCharm, etc.):
1. Go to Settings > Editor > Code Style
2. Set "Line separator" to your preferred format
3. Can also be set in .editorconfig

Create an .editorconfig file (works with most editors):

ini
# .editorconfig
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8

[*.{bat,cmd,ps1}]
end_of_line = crlf

Most modern editors support EditorConfig natively or via plugins.

6Suppress the warning (if you just want it to go away)

If you understand the behavior and just want to suppress the warning:

Option 1: Set safecrlf to false (suppresses the warning)

bash
git config --global core.safecrlf false

Note: This only suppresses the warning. Line ending conversion still happens based on core.autocrlf.

Option 2: Use quiet mode for add

bash
git add . 2>/dev/null

Option 3: Accept that warnings are informational
The warning doesn't prevent any operations. If your project works correctly, you can simply ignore it.

When NOT to suppress:
- If you're unsure about your line ending configuration
- If you're seeing related issues (weird diffs, merge conflicts)
- If team members report problems with line endings

The warning exists to help you catch configuration issues early.

7Fix specific files with wrong line endings

If specific files have wrong line endings that you need to fix:

Convert a file from CRLF to LF:

On Linux/macOS/WSL:

bash
# Using sed
sed -i 's/\r$//' filename.txt

# Using dos2unix (install if needed: apt install dos2unix)
dos2unix filename.txt

# Using tr
tr -d '\r' < filename.txt > filename.tmp && mv filename.tmp filename.txt

On Windows with Git Bash:

bash
dos2unix filename.txt

# Or using sed
sed -i 's/\r$//' filename.txt

On Windows with PowerShell:

powershell
(Get-Content filename.txt -Raw) -replace "\r\n", "\n" | Set-Content filename.txt -NoNewline

Convert a file from LF to CRLF:

bash
# Using unix2dos
unix2dos filename.txt

# Using sed
sed -i 's/$/\r/' filename.txt

Bulk convert all files:

bash
# Find and convert all text files to LF
find . -type f -name "*.txt" -exec dos2unix {} \;
find . -type f -name "*.sh" -exec dos2unix {} \;

Advanced notes

Understanding Line Endings in Depth:

Historical Context:
- CR (\r, 0x0D): Carriage Return - moves cursor to start of line (old Macs)
- LF (\n, 0x0A): Line Feed - moves cursor down one line (Unix/Linux/macOS)
- CRLF (\r\n): Both characters - standard for Windows/DOS

Old typewriters needed both: CR to move the carriage back, LF to advance the paper. Windows inherited this from DOS, which came from CP/M.

The core.autocrlf Matrix:

| Setting | On checkout | On commit | Best for |
|---------|------------|-----------|----------|
| true | LF → CRLF | CRLF → LF | Windows developers |
| input | No change | CRLF → LF | Cross-platform, keep LF |
| false | No change | No change | When you manage it yourself |

The Opposite Warning:

You might also see:

bash
warning: CRLF will be replaced by LF in file.txt

This happens when:
- autocrlf = input or autocrlf = true
- You add a file with CRLF endings
- Git will convert to LF in the repository

Why .gitattributes is Better Than core.autocrlf:

1. Repository-specific: Settings travel with the repo
2. Per-file control: Different rules for different file types
3. Team consistency: Everyone uses the same settings
4. Override user config: Works regardless of local Git settings

The text=auto Attribute:

gitattributes
* text=auto

This tells Git to:
1. Auto-detect whether a file is text or binary
2. Apply line ending conversion only to text files
3. Use the platform's native line endings on checkout

Forcing Line Endings for Specific Files:

gitattributes
# Always use LF (for shell scripts)
*.sh text eol=lf

# Always use CRLF (for Windows batch files)
*.bat text eol=crlf

# Never convert (treat as binary)
*.png binary

# Force text handling even if binary chars detected
*.svg text

The eol Attribute:
- eol=lf: Always checkout with LF
- eol=crlf: Always checkout with CRLF
- Without eol: Use native line endings based on platform

Common Pitfalls:

1. Mixed line endings in a file: Some lines CRLF, some LF. Git may not detect this well. Use tools like file or dos2unix to diagnose.

2. Binary files detected as text: Git might try to convert binary files, corrupting them. Use .gitattributes to mark them as binary.

3. Scripts failing on Unix: Shell scripts with CRLF won't run:

bash
/bin/bash^M: bad interpreter: No such file or directory

Always use eol=lf for shell scripts.

4. Git hooks with CRLF: Hooks in .git/hooks or committed hooks won't execute if they have Windows line endings on Unix systems.

WSL and Docker Considerations:

When using WSL (Windows Subsystem for Linux) or Docker on Windows:
- Files on Windows filesystem (/mnt/c/) may have CRLF
- Files on Linux filesystem may have LF
- Git in WSL may behave differently than Git for Windows
- Consider where your repo lives and which Git you're using

Checking File Line Endings:

bash
# Show line ending type
file filename.txt
# Output: "filename.txt: ASCII text" (LF) or "ASCII text, with CRLF line terminators"

# Show actual bytes (look for 0d 0a = CRLF)
hexdump -C filename.txt | head

# Count line ending types in a file
cat filename.txt | od -c | grep -c '\r'

Git Configuration Hierarchy:

Line ending settings can be set at multiple levels (later overrides earlier):
1. System: git config --system
2. Global: git config --global
3. Repository: git config --local
4. Worktree: git config --worktree
5. .gitattributes: Per-file overrides

Use git config --show-origin core.autocrlf to see where the setting comes from.

Frequently asked questions

What does "warning: LF will be replaced by CRLF in file.txt. The file will have i" mean?
The "LF will be replaced by CRLF" warning tells you that Git is automatically converting line endings in your files. This happens because: LF (Line Feed, \n) is the Unix/Linux/macOS line ending standard. CRLF (Carriage Return + Line Feed, \r\n) is the Windows line ending standard.
How do I fix "warning: LF will be replaced by CRLF in file.txt. The file will have i"?
This Git warning appears on Windows when files have Unix-style line endings (LF) but Git is configured to convert them to Windows-style (CRLF). While not an error, this indicates a line ending configuration mismatch that can cause issues in cross-platform projects. Configure core.autocrlf appropriately or use .gitattributes for consistent handling.
What causes "warning: LF will be replaced by CRLF in file.txt. The file will have i"?
core.autocrlf is set to 'true' and files have LF line endings Files were created on Unix/Linux/macOS and are being added on Windows Editor is configured to use LF line endings by default (VS Code, Sublime, etc.)
Is the "warning: LF will be replaced by CRLF in file.txt. The file will have i" error serious?
It is a low-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading