Search code examples
windowsgitdockerunixline-endings

Git Line Endings problem on a Windows shared volume with a Unix docker container


I'm working on Windows and use centOS docker containers for my development. I also have a volume shared between my containers and a local folder.

The problem is: when cloning a repository from windows into the shared volume or from the container into the shared volume, a git status does not return the same thing when it is executed in the container and on the local machine. I expect it to be the same and tried different configurations without success:

  • git config --global core.autocrlf true/input/false on the local machine and in the container
  • git config --global core.crlf true/false/auto on the local machine and in the container
  • git config --global core.eol lf ...

Does anyone have the right configuration of Git to get an identical git status from the container and on the local machine without modifying the .gitattributes?


Solution

  • The way to configure line endings is:

    On Linux:

    git config --global core.autocrlf input
    

    On Windows:

    git config --global core.autocrlf true
    

    You can also set repository-specific configurations:

    cd /path/to/repo
    git config core.autocrtlf <value>
    

    In your situation, it sounds that if you set git config --global core.autocrlf input in your CentOS containers and git config --global core.autocrlf true for your Windows machine, you shouldn't have issues.