Search code examples
git

Git shows warning for extra space at end of line in readme file


I'm writing a README.md. I've added an extra space at the end of some lines. When I do git diff shows this as highlighted as below

Git warning on extra space after a line

Why the trailing whitespace is considered an error?


Solution

  • Git will show you "common whitespace problems" such as trailing whitespace. You can control this behavior with the core.whitespace configuration option. -trailing-space will turn this highlighting off.

    [core]
            whitespace = -trailing-space
    

    I've never understood why this is considered a problem, but many people do, so I recommend stripping them off. You can configure your editor to strip trailing whitespace for you. If doing this for all documents doesn't appeal to you, use EditorConfig to provide universal editor configurations for your projects.

    root = true
    
    [*]
    trim_trailing_whitespace = true
    insert_final_newline = true
    

    See also