Most of the times I keep encountering this issue and I have to google around how to fix it.. So, writing a blog for my future self to just refer from here and it might help others as well...
There are certain solutions which require changing into prettier
or eslint
config but the following solution works without those changes.
Problem
-
Windows: Uses both carriage return (
CR
) and line feed (LF
) — written asCRLF
. -
Linux and modern macOS: Use only line feed (
LF
).
These differences can cause compatibility problems when sharing or collaborating on code across different environments.
The Role of Git’s core.autocrlf
Git offers a configuration setting called core.autocrlf
to manage line ending conversions:
- On Windows, this is typically set to
true
by default. - When
core.autocrlf
istrue
, Git automatically converts line endings toCRLF
when checking out files. - When committing, Git converts them back to
LF
to store in the repository.
The Problem in Practice
When cloning a project on a Windows machine: Git converts all file line endings to CRLF
in your local working directory.
Solution
To avoid automatic line ending conversions by Git, you can disable the behavior with the following command:
git config --global core.autocrlf false
This tells Git not to modify line endings when checking out or committing files. It helps maintain consistent line endings, which is especially useful when collaborating across different operating systems.
Note: After updating this setting, it's recommended to delete your local repository and clone it again. This ensures that all files are pulled with the correct line endings according to the new configuration.
Top comments (0)