Solve Script Issues with GitAttributes

Solve Script Running Issues with .gitattributes


Today at work I was running into a pesky error when trying to run a service with docker-compose up.

The error:

internal-service    | /bin/sh: ./ not found

I had used a team GraphQL service template to generate my service and what was strange was that the current services not using the template were running fine with Docker Compose but every single one I generated failed!


After seeing that the problem was not just in my service but in the docker config of the template itself, I knew I had to contact the developer of the template. First we were stumped -the docker-compose.yml, Dockerfile, and aws.yml files were identical between working services and the ones failing based off of the template. But after some digging with the other developer, he suggested line endings being the problem:

bash-4.4$ ./
bash: ./ /bin/bash^M: bad interpreter: No such file or directory

In which the setup script he wrote contained Windows line CLRF endings, and when run in a Linux environment the lines caused a syntax error.

I was sure this was a common problem and sure enough I found articles that helped me discover .gitattributes files:


So the problem was that Windows CLRF line endings were causing our script to fail.

At this point, it was a simple fix using a .gitattributes file, which I will be using for future projects.

  • touch .gitattributes
  • Add to the file:

    * text=auto
    *.sh text eol=lf
  • git add --renormalize . : Change all line endings
  • git push : Problem solved!