Git: LF will be replaced by CRLF the next time Git touches it
The warning describes the next checkout, not the commit. core.autocrlf and .gitattributes decide it; scripts need eol=lf or they break on Linux.

Introduction & Quick Summary
warning: in the working copy of 'scripts/deploy.sh', LF will be replaced by CRLF
the next time Git touches itGit is telling you that its line-ending policy will rewrite the file at the next checkout, not that the file is broken. The warning appears during git add when the working tree contains one ending style and the index or checkout policy expects another.
Two settings decide the behavior, and they are frequently confused:
core.autocrlf— a per-machine preference:trueconverts on commit and checkout (Windows default),inputconverts only on commit (recommended for macOS/Linux),falsestores bytes as-is..gitattributestext/eol— a per-repository rule that overrides the machine preference and travels with the code.
The warning itself is harmless. The bug it predicts is not: a shell script committed with CRLF fails on Linux with /usr/bin/env: 'bash\r': No such file or directory, and a .bat file normalized to LF breaks cmd.exe.
core.autocrlf | On commit | On checkout | Typical host |
|---|---|---|---|
true | CRLF to LF | LF to CRLF | Windows default |
input | CRLF to LF | No conversion | macOS, Linux |
false | No conversion | No conversion | Servers, CI |
| unset | No conversion | No conversion | Git default |
Core Mechanics, Signatures & Reproducible Setup
Git stores blobs in the index. For paths marked as text, git add normalizes line endings to LF in the index, and git checkout materializes them according to the checkout rule. The warning is emitted when normalization is about to change the working tree content in a way the user did not explicitly request.
Reproduce it on Linux by forcing an autocrlf-style conversion:
mkdir crlf-demo && cd crlf-demo
git init -q
printf 'echo hello\n' > deploy.sh
git config core.autocrlf true
git add deploy.sh
# warning: in the working copy of 'deploy.sh', LF will be replaced by CRLF
# the next time Git touches itThe blob in the index now contains LF, and the next git checkout -- deploy.sh writes CRLF into the working tree. Inspect what is actually stored:
git ls-files --eol
# i/lf w/crlf attr/ deploy.sh
# ^index ^worktreei/ is the index, w/ is the working tree, and attr/ shows the attribute that applied. This single command answers most line-ending questions faster than any config dump.
The repository-level fix is a .gitattributes file at the root:
* text=auto
*.sh text eol=lf
*.py text eol=lf
*.bat text eol=crlf
*.cmd text eol=crlf
*.png binary
*.jpg binary
*.pdf binarytext=auto lets Git detect text files and normalize them; explicit eol overrides the platform-dependent checkout for files whose consumer requires a specific ending. binary is shorthand for -text -diff, which keeps the bytes untouched.
After adding the file, renormalize the existing history's working tree once:
git add --renormalize .
git status
git commit -m "Normalize line endings"--renormalize re-adds tracked files so the index is rewritten according to the new attributes. It does not rewrite history; older commits keep their bytes, and only the new commit changes them.
Key Comparison Table
| Setting | Where it lives | Overrides the other | Good for |
|---|---|---|---|
core.autocrlf=true | Machine config | Loses to eol= attributes | Windows-only teams |
core.autocrlf=input | Machine config | Loses to eol= attributes | Mixed-OS teams |
text=auto | .gitattributes | Beats autocrlf | Repositories |
eol=lf | .gitattributes | Beats everything | Shell scripts, Dockerfiles |
eol=crlf | .gitattributes | Beats everything | Batch files |
-text / binary | .gitattributes | Disables all conversion | Images, archives |
| Symptom | Cause | Fix |
|---|---|---|
Warning on git add | Working tree differs from policy | Expected; commit or renormalize |
Script fails with \r | File committed with CRLF | eol=lf plus renormalize |
| Whole file shows as changed | Autocrlf changed on one machine | Renormalize, then commit once |
| Warning persists after commit | Policy converts back on checkout | Set eol=lf for that path |
| Binary file corrupted | Text detection on image | Mark binary |
Practical Edge Cases, Error Fixes & Deep Dive Code Examples
Case 1: The warning is not an error, but the script really breaks
bash scripts/deploy.sh
# /usr/bin/env: 'bash\r': No such file or directoryCheck the actual bytes before changing any configuration:
file scripts/deploy.sh
# scripts/deploy.sh: Bourne-Again shell script, ASCII text, with CRLF line terminatorsThen fix the policy for that path and renormalize:
printf '*.sh text eol=lf\n' >> .gitattributes
git add --renormalize scripts/deploy.sh
git commit -m "Force LF for shell scripts"dos2unix or sed -i 's/\r$//' fixes the working copy but not the next checkout, so it is a temporary measure on a machine without write access to .gitattributes.
Case 2: A repository that already contains CRLF blobs
$ git ls-files --eol | grep crlf
i/crlf w/crlf attr/ src/legacy.bat
i/mixed w/mixed attr/ src/config.iniAn i/crlf entry means the index itself stores CRLF, so no checkout policy will normalize it. Adding text=auto and renormalizing rewrites every such file in one commit; review the diff size before pushing, because reviewers on GitHub will see entire files change.
git add --renormalize .
git diff --cached --stat | tail -3
# 142 files changed, 142 insertions(+), 142 deletions(-)Case 3: safecrlf turns the warning into a failure
git config --global core.safecrlf true
git add data.csv
# fatal: LF would be replaced by CRLF in data.csvsafecrlf=true refuses any irreversible conversion. safecrlf=warn keeps the warning without failing. Use true on a team that keeps losing scripts, and mark the genuine exceptions with -text so they are not blocked.
Case 4: Docker and CI builds see different endings
A Dockerfile or entrypoint script committed from Windows with CRLF fails at container start:
exec /usr/local/bin/entrypoint.sh: no such file or directoryThe error is confusing because the file exists. The interpreter path is what does not exist, since the kernel reads #!/bin/sh\r as an interpreter name. Mark scripts in .gitattributes, and add a build-time guard for repositories with many contributors:
COPY . /app
RUN sed -i 's/\r$//' /app/entrypoint.sh && chmod +x /app/entrypoint.shThe sed is a safety net, not a substitute for the attribute; without it a future script reintroduces the bug.
Case 5: Editors rewriting endings silently
VS Code, JetBrains and Notepad++ each have their own files.eol or line separator setting. A file saved as CRLF on a machine with autocrlf=input produces the opposite warning (CRLF will be replaced by LF) on every save, and one file can flip back and forth between developers.
Pin the editor to the repository convention rather than the host OS:
{
"files.eol": "\n",
"files.insertFinalNewline": true
}Then confirm with git ls-files --eol after a save; if w/ still shows crlf, the editor setting did not apply to that file type.
Case 6: Global config versus repository config
git config --show-origin --get core.autocrlf
# file:/home/dev/.gitconfig input--show-origin reveals whether the value comes from the system, global, or local config. A repository that sets core.autocrlf=true locally overrides the machine default for everyone who clones it only if the setting is written to .git/config, which does not travel; use .gitattributes for anything the team must share.
Common Compilation/Runtime Mistakes & Version Gotchas
- Assuming the warning means data loss. The commit is normalized as intended; the warning describes the next checkout. Committing and verifying with
git ls-files --eolis the correct response. core.autocrlfon Linux servers. Setting it totrueon a Linux build host converts LF to CRLF on checkout, which breaks scripts that were fine in the repository. Useinputorfalseoutside Windows.- Git for Windows defaults. The installer selects
trueby default, so a Windows developer sees these warnings on repositories with no.gitattributes. Changing the machine setting does not fix repositories that already store CRLF blobs. .gitattributesplacement. Only the root file applies repository-wide; a nested.gitattributesapplies to its directory subtree, and a file added before the attribute still needs renormalization.text=autoand.batfiles. Automatic detection sees batch files as text and converts them to LF in the index; withouteol=crlffor*.bat, a Windows checkout may still produce a filecmd.exemisparses.--renormalizewith uncommitted work. It stages all tracked files, so run it on a clean tree or stash first. Otherwise an unrelated change is buried in a thousand-line line-ending commit.
When a diff looks like the whole file changed, the diff tool shows whether the only difference is \r. To confirm two checkouts are byte-identical after normalization, compare their hashes with the hash generator.
Primary references: gitattributes defines text, eol and binary with their precedence, and Git configuration documents core.autocrlf and core.safecrlf.
Official references
primary documentationThe Git documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Git work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Git guides
All Git guidesGit: fatal: not a git repository (or any parent): .git
The command ran outside a working tree or the .git metadata is gone. Confirm the root, restore a deleted .git, and repair worktree pointers.
Git: fatal: unable to auto-detect email address
A commit needs an author identity. Containers and fresh installs have no user.email, so Git guesses from the OS user and refuses to continue.
Git: could not read Username, terminal prompts disabled
A headless git has no terminal to ask for credentials. Supply a token through a helper, a header or SSH instead of relying on a prompt.
Git: The current branch has no upstream branch
The branch exists locally with no tracking configured. Set upstream once with push -u, or let push.autoSetupRemote do it on every new branch.
More in Git
All Git guidesThe guides filed next to this one in Git, in library order.