Use Unix line endings

How to set Git and Grunt to always use same line ending character.

Once in a while, I need to develop something using Windows laptop, and that always causes end of the line problems. Here is how to prevent them once and for all.

Make sure your editor uses Unix line endings. For example, in Sublime you can set user preference "default_line_ending": "unix"

Turn off Git line ending conversion to system's native one

git config --global core.autocrlf false

Tell Git that LF (unix) should be the default one

git config --global core.eol lf

Install grunt-lineending plugin.

npm install grunt-lineending --save-dev

The line endings mostly affect the first file used for Node command line tools with shebang line #!/usr/bin/env node, usually I only convert only line endings in this file. Here is typical grunt configuration

1
2
3
4
5
6
7
8
9
10
11
lineending: {
index: {
options: {
eol: 'lf'
},
files: {
'index.js': 'index.js'
}
}
}
grunt.registerTask('default', ['pre-check', 'lineending']);

Examples: next-update, gt