How to Silence the git add LF/CRLF Warning
If git add prints warning: in the working copy of 'app.js', LF will be replaced by CRLF the next time Git touches it, it is because the line-ending conversion setting core.autocrlf is set to true. The git add itself succeeds, and the file enters the repository with LF. If you want to keep LF line endings, set core.autocrlf to input or false, or put a .gitattributes file in the repository with * text=auto eol=lf. Either way, the warning stops appearing.
This warning often shows up when the same repository is used on both Windows and Linux or macOS. I reproduced the warning in my test environment and included the messages exactly as they were printed. I also confirmed that changing the setting makes the warning disappear for the same file.
The test environment was Ubuntu 24.04 with Git 2.43.0. On Linux, I set core.autocrlf to true myself to trigger the warning. I used a placeholder name and email address (Neko <neko@example.com>), set the default branch name to main, and fixed the commit date with environment variables. Commit hashes and similar values will differ on your machine. I did not test Windows or macOS, or the line-ending option in the Git for Windows installer.
- 1. Reproducing the warning
- 2. The warning means "this will become CRLF the next time it is checked out"
- 3. Finding where core.autocrlf is set
- 4. Changing it only on your machine: set core.autocrlf to input or false
- 5. Deciding line endings in the repository: put eol=lf in .gitattributes
- 6. Setting core.safecrlf to false does not stop the conversion
Reproducing the warning
I set core.autocrlf to true and ran git add on app.js and README.md, which both have LF line endings. cat -A shows line ends as $ and CR as ^M. If a line ends with only $, it is LF.
$ git config --global core.autocrlf true
$ git init -q
$ printf "console.log(\"hello\");\n" > app.js
$ printf "# Demo\n" > README.md
$ cat -A app.js
console.log("hello");$
$ git add .; echo "exit=$?"
warning: in the working copy of 'README.md', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'app.js', LF will be replaced by CRLF the next time Git touches it
exit=0
One warning was printed for each file. However, the exit code was 0, and git status shows that both files are staged.
$ git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
new file: app.js
The warning means "this will become CRLF the next time it is checked out"
git ls-files --eol shows each file's line endings separately for the index (i/) and the working copy (w/) (git ls-files reference). Right after git add, both are LF.
$ git ls-files --eol
i/lf w/lf attr/ README.md
i/lf w/lf attr/ app.js
After committing, I deleted app.js and restored it with git checkout. The working copy became CRLF (the line end shows as ^M$). The committed content stayed LF.
$ git commit -q -m "最初のコミット" && git log --oneline
414e77b 最初のコミット
$ rm app.js && git checkout -- app.js
$ cat -A app.js
console.log("hello");^M$
$ git ls-files --eol
i/lf w/lf attr/ README.md
i/lf w/crlf attr/ app.js
$ git show HEAD:app.js | cat -A
console.log("hello");$

The core.autocrlf reference says that true is meant for a working copy with CRLF and a repository with LF. A file that is LF now will change to CRLF the next time Git writes it out. The warning's "the next time Git touches it" gives this notice in advance.
In contrast, adding a file that was already saved with CRLF produced no warning. It enters the repository as LF, and the working copy stays CRLF, so nothing changes.
$ printf "a\r\nb\r\n" > crlf.txt && git add crlf.txt; echo "exit=$?"
exit=0
$ git ls-files --eol crlf.txt
i/lf w/crlf attr/ crlf.txt
Finding where core.autocrlf is set
Before choosing a fix, I checked where core.autocrlf is set. Adding --show-scope to git config shows the value along with its scope, such as system, global, or local (git config reference).
$ git config --show-scope --get-all core.autocrlf
global true
In this example, the value true came from the per-user setting (--global). A setting written with --global applies to all repositories for that user. Running git config without --global writes only to that repository's .git/config.
Changing it only on your machine: set core.autocrlf to input or false
If you want to keep line endings as LF, set core.autocrlf to input. I compared the results before and after the change with a newly created util.js. Before, the warning was printed. After I set input, nothing was printed.
$ printf "export const x = 1;\n" > util.js
$ git add util.js; echo "exit=$?"
warning: in the working copy of 'util.js', LF will be replaced by CRLF the next time Git touches it
exit=0
$ git reset -q util.js
$ git config --global core.autocrlf input
$ git add util.js; echo "exit=$?"
exit=0
$ git ls-files --eol util.js
i/lf w/lf attr/ util.js
With input, Git converts CRLF to LF when adding, but does not convert anything when checking out. So when I added a CRLF file while input was set, a warning in the opposite direction appeared.
$ printf "a\r\nb\r\n" > crlf.txt && git add crlf.txt; echo "exit=$?"
warning: in the working copy of 'crlf.txt', CRLF will be replaced by LF the next time Git touches it
exit=0
With false, Git does no conversion at all, so adding util.js produced no warning. The core.autocrlf section of Pro Git, the official Git book, recommends true on Windows, input on Linux and macOS, and false for a Windows-only project where you want CR to be recorded as is.
Deciding line endings in the repository: put eol=lf in .gitattributes
As described above, core.autocrlf is a setting written per user (or in the repository's .git/config), and it is not committed. Placing a .gitattributes file at the top of the repository lets you decide how line endings are handled inside the repository. The gitattributes reference says that settings you want to share with others belong in .gitattributes.
I set core.autocrlf back to true and compared the results before and after adding .gitattributes.
$ git config --global core.autocrlf true
$ git add util.js; echo "exit=$?"
warning: in the working copy of 'util.js', LF will be replaced by CRLF the next time Git touches it
exit=0
$ git reset -q util.js
$ printf "* text=auto eol=lf\n" > .gitattributes
$ cat .gitattributes
* text=auto eol=lf
$ git add .gitattributes util.js; echo "exit=$?"
exit=0
text=auto tells Git to detect whether a file is text or binary, and converts line endings only for text files. eol=lf makes checkout produce LF, matching the index. Both are described in the official reference. Even with core.autocrlf still set to true, adding util.js after placing .gitattributes no longer produced a warning.
Files already checked out with CRLF stay as they are
Adding .gitattributes does not rewrite line endings in working-copy files that already exist. In git ls-files --eol, only app.js, which I checked out as CRLF earlier while testing the warning, remains w/crlf.
$ git ls-files --eol
i/lf w/lf attr/text=auto eol=lf .gitattributes
i/lf w/lf attr/text=auto eol=lf README.md
i/lf w/crlf attr/text=auto eol=lf app.js
i/lf w/lf attr/text=auto eol=lf util.js
After I deleted app.js and checked it out again, it became LF.
$ rm app.js && git checkout -- app.js
$ cat -A app.js
console.log("hello");$
$ git ls-files --eol app.js
i/lf w/lf attr/text=auto eol=lf app.js
Deleting a file with rm and checking it out again discards any changes you have not committed. In my test environment, when I edited app.js and then ran rm and git checkout --, the file went back to its content from before the edit. Commit files that have changes before you check them out again.
Setting core.safecrlf to false does not stop the conversion
Whether this warning appears is also controlled by a setting called core.safecrlf. In a different repository (with core.autocrlf set to true), I created a.txt and b.txt, both with LF line endings, and tested. git -c setting=value changes the setting only for that one command. With false, no warning was printed. However, when the file is checked out again, it becomes CRLF. The warning disappears, but the conversion does not stop.
$ git -c core.safecrlf=false add b.txt; echo "exit=$?"
exit=0
$ git commit -q -m "b" && rm b.txt && git checkout -- b.txt && cat -A b.txt
b^M$
With true, the message becomes an error instead of a warning, and the file is not staged.
$ git -c core.safecrlf=true add a.txt; echo "exit=$?"
fatal: LF would be replaced by CRLF in a.txt
exit=128
The core.safecrlf reference says that true refuses conversions that cannot be reversed, and warn prints a warning and continues. If you want to remove the warning, decide whether working-copy files should use LF or CRLF with core.autocrlf or .gitattributes.





