How to Ensure Always LF (Line Feed) Instead of CRLF on Windows — JetBrains, PhpStorm, WebStorm, Git

Prakash Bhandari (PB)

Prakash Bhandari (PB)Loading..

Published:

 Like 
Bookmark    

As a Web Application Developer working on open-source and cross-platform projects, I’ve run into line-ending issues more times than I can count. One of the most annoying ones? Files randomly using CRLF instead of LF, leading to unnecessary Git diffs and inconsistencies across teams.

After a few frustrating experiences with CRLF sneaking into my commits, especially in PhpStorm and WebStorm, I decided to permanently fix it. Here's how I did it — and how you can too.

 

Why Line Endings Matter

Windows uses CRLF (\r\n) by default, while Unix-based systems (like Linux/macOS) use LF (\n). While it may seem minor, inconsistent line endings can cause:

  • Conflicts in version control (Git diffs everywhere)
  • Build or linting failures (in strict CI/CD setups)
  • Code review headaches

If you're collaborating across OSes, standardizing on LF is the cleanest solution.

 

Step-by-Step Solution

1. Set Line Endings in PhpStorm/WebStorm

I use JetBrains IDEs such as PhpStorm, WebStorm, IntelliJ IDEA, etc. for most of my work, and here’s how I made sure it always uses LF:

  • Go to: File > Settings (Ctrl + Alt + S)
  • Navigate to: Editor > Code Style
  • At the top, find Line separator (for new files)
  • Set it to: Unix and macOS (\n)
     

Tip: Already opened a file with CRLF? Look at the bottom-right status bar — click on CRLF, change to LF, and hit save.

 

2. Use a .editorconfig File (Recommended)

Adding a .editorconfig file to the root of my projects was a game-changer. It enforces consistent settings across IDEs.

Here’s what I use:

# .editorconfig
root = true

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

PhpStorm and WebStorm support .editorconfig natively, so it just works.

 

3. Configure Git to Handle LF Correctly

I noticed that even with the IDE configured, Git sometimes picked up CRLF lines if I wasn’t careful.

To fix that, I ran:

git config --global core.autocrlf input

This tells Git to:

  • Convert CRLF → LF when committing (on input)
  • Leave LF files alone

It’s the best setting if you’re on Windows but collaborating with Linux/mac users.

If you only want this for one project:

git config core.autocrlf input

 

4. Fix Existing Files

After changing all those settings, I still had older files using CRLF. Here's how I cleaned them up:

Option 1 – PhpStorm:

  • Open the file
  • Click on CRLF in status bar → switch to LF
  • Save

Option 2 – Batch Convert (for advanced users):

find . -type f -name "*.php" -exec dos2unix {} \;

 

Make sure dos2unix is installed on your system. You can also use VSCode extensions or tools like Prettier to auto-format line endings.

 

Final Thoughts

Ever since I locked in these settings, I've had zero issues with line endings, even on large, multi-developer projects. Clean commits, happier linters, and smoother merges.

If you're using Windows and collaborating cross-platform, I highly recommend taking a few minutes to lock this down — your team (and your future self) will thank you.

Want to Share or Ask?

Have you faced similar issues? Or maybe you’ve got a different setup?
Feel free to leave a comment below and let’s discuss

Discussion (0)

Login to Post Comment!