How to make Git ignore different line endings

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

Getting errors like these, and want to deliberately ignore them?

If you don’t know why you would, you should read this great blogpost about line endings in Git by Tim Clem.

Don’t look at line endings!

In some cases you want to ignore these errors. In my specific situation i don’t want Git to warn me about the line endings, because my IDE takes care of that. I work in a project with multiple people, and *somewhere* in the process some files with different line endings than the project standard slipped into the repo. It happens. Your Git could be configured so that it automatically corrects the file line endings for you when you pull this code.  And this can be pretty annoying.

You can change this behaviour, but again, to avoid problems you have to know the reason why you get these errors. Be sure you know, see the link earlier in this post.

You can disable the CRLF behaviour completely, or per filetype by changing entries in your .gitattributes file. In my case, i put this:

* -crlf

This tells git to ignore the line endings for all files. And does not change the files in your working directory. Even if you have the core.autocrlf set to true, false, or input.

Share this post:
    • brettalton

      Does this work during a –diff however? It doesn’t appear to ignore the line endings if the changes have already been committed. I would be interested in seeing how you can compare two branches while ignoring the line ending.

    • Herf

      Couldn’t you use “* -crlf -diff” to handle the diff case?

      • stairbob

        No, that just makes git say “binary files […] differ” without showing any diff.

    • Jen Wilson

      I don’t understand why you Git fanbois can’t tell the truth. It is garbage, and it does not handle line endings correctly. Your claim above is a boldface lie. Even if you add what you claim to .gitattributes, Git will still get confused by line ending problems and lie about what has changed. Linus hates users and he hates DOS users more. Because I use that Windows garbage, he wants me to die, and his over the top attacks on us to try to keep us from working shows just how horrible his kind is.

    • Markus Peröbner

      I think the link to .gitattributes changed to ?

    • Lawrence

      You deserve a medal. Thank you very much!

    • Great stuff, thanks.

    • stairbob

      Am I misunderstanding something?

      $ cat .gitattributes
      * -crlf
      $ git diff | grep -C1 newline
      No newline at end of file


      No newline at end of file