When working on different operating systems, managing line endings is crucial to ensure consistency and avoid issues in a collaborative development environment. Here are the recommendations for configuring Git to handle line endings on Windows, WSL2, and Ubuntu:
-
Recommended Setting:
core.autocrlf true
-
Command:
git config --global core.autocrlf true
-
Behavior: Converts LF to CRLF on checkout, and CRLF to LF on commit. This ensures that text files contain the correct line endings when working on Windows, while preserving LF line endings in the repository.
-
Recommended Setting:
core.autocrlf input
orcore.autocrlf false
-
Command:
git config --global core.autocrlf input
or
git config --global core.autocrlf false
-
Behavior:
input
: Converts CRLF to LF on commit, no conversion on checkout.false
: No conversion on checkout or commit. Line endings are preserved as-is.
-
Recommended Setting:
core.autocrlf input
orcore.autocrlf false
-
Command:
git config --global core.autocrlf input
or
git config --global core.autocrlf false
-
Behavior:
input
: Converts CRLF to LF on commit, no conversion on checkout.false
: No conversion on checkout or commit. Line endings are preserved as-is.
- For a shared project, it's advisable to include a
.gitattributes
file in the repository to enforce consistent line ending settings across different environments.* text=auto
If the repository has been checked out prior to setting the core.autocrlf configuration, you might want to re-normalize the line endings in your repository: