Skip to content

Instantly share code, notes, and snippets.

@ndamulelonemakh
Last active February 7, 2024 08:35
Show Gist options
  • Save ndamulelonemakh/b6266b9576395f690fe30db764e213d3 to your computer and use it in GitHub Desktop.
Save ndamulelonemakh/b6266b9576395f690fe30db764e213d3 to your computer and use it in GitHub Desktop.
Handle CRLF and LF settings when working on Windows and Linux environments

Handling Line Endings: Windows, WSL2, and Ubuntu

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:

1. Windows:

  • 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.

2. WSL2 (Windows Subsystem for Linux 2):

  • Recommended Setting: core.autocrlf input or core.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.

3. Ubuntu:

  • Recommended Setting: core.autocrlf input or core.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.

Additional Note:

  • 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
    
@ndamulelonemakh
Copy link
Author

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:

git add --renormalize .
git commit -m "Normalized line endings"
git push

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment