title: How to force consistent line endings in Git commits with cross-platform compatibility
body: <p>I am having issues with merge conflicts due to line endings while working with someone who uses a different OS. I work on Windows and my colleague is on Mac. When he pushes his changes, sometimes files he hasn't worked on show up in the diff as being changed, because the line endings now show <code>^M</code> on each file. This has lead to merge conflicts. I read in the Git docs the following:</p>
  
  <blockquote>
    <p>Git can handle this by auto-converting CRLF line endings into LF when
    you add a file to the index, and vice versa when it checks out code
    onto your filesystem. You can turn on this functionality with the
    core.autocrlf setting. If you’re on a Windows machine, set it to
    true — this converts LF endings into CRLF when you check out code:</p>
    
    <p>$ git config --global core.autocrlf true If you’re on a Linux or macOS
    system that uses LF line endings, then you don’t want Git to
    automatically convert them when you check out files; however, if a
    file with CRLF endings accidentally gets introduced, then you may want
    Git to fix it. You can tell Git to convert CRLF to LF on commit but
    not the other way around by setting core.autocrlf to input:</p>
    
    <p>$ git config --global core.autocrlf input This setup should leave you
    with CRLF endings in Windows checkouts, but LF endings on macOS and
    Linux systems and in the repository.</p>
  </blockquote>
  
  <p>This makes sense, but I am still unclear on how the files are actually committed in the repo. For example, if he creates a file on his system, it will have all <code>LF</code> line endings, correct? So when he commits, I presume those line endings are retained as-is. When I pull, my <code>autocrlf</code> being <code>true</code> will check them out with <code>CRLF</code> line endings, as far as I understand. (I get the warnings <code>warning: LF will be replaced by CRLF in &lt;file x&gt;; The file will have its original line endings in your working directory</code>)</p>
  
  <p>A couple questions about this: when the warning says "working directory", what is that referring to? Also, when I then make changes, or create other files, all of which have the <code>CRLF</code> line endings and commit+push, are they stored in the repo as <code>CRLF</code> or <code>LF</code>?</p>
  
  <p>I imagine the ideal is to have the repo strip anything but <code>LF</code> everytime a commit is made; is this what happens? What's going on under the hood and how can we force this to behave consistently?</p>