Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use multiple environments thanks to virtual machines, and my code directory is shared between them. I also like my code to have the native (host) line endings.

When I'm on a Windows host, I checkout my code and line endings are converted to \r\n (and it's OK for me). But when I want to execute a shell script from my Linux virtual machine, I get errors telling me the /bin/sh^M doesn't exist.

Can I tell Git to keep Unix endings for this specific file? Is there a better way to deal with line endings on multiple environments?

share|improve this question
up vote 1 down vote accepted

For a single file, create a .gitattributes file containing:

*.sh    eol=lf

(Another possible setting is -text, which simply disables line ending conversion.)

share|improve this answer
-text will do other things too that you don't want, like stop showing diffs for the file. – Arrowmaster Jan 29 '11 at 19:48

You can run dos2unix on the files to format them properly for linux/unix.

share|improve this answer
It would make the file look completely different to the VCS. – Warren Seine Jan 29 '11 at 21:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.