gitsyntaxconfiguration-files

Does `~/.gitconfig` syntax require spaces, tabs, or either for indenting?


I was editing my ~/.gitconfig and noticed there was mixed tabs/spaces. Usually mixing tabs/spaces is bad but when I tried to look up the documentation for what is allowed syntax requirement I couldn't find an answer.

Does ~/.gitconfig syntax require spaces, tabs, or either for indenting?

Where is this explained in the git-config documentation?


Solution

  • No, .gitconfig does not require spaces and/or tabs for indenting.

    Whitespace at the start of each line is ignored, which means you're free to indent or not indent, spaces or tabs, it doesn't matter.

    Only whitespace inside values is retained verbatim, other whitespace is ignored.

    So feel free to use spaces and/or tabs as you see fit, or just remove indentation altogether.

    Note that the gitconfig syntax allows you to continue lines onto the next line, whitespace inside such lines will be kept, but here:

     name = value
    ^    ^ ^     ^
    

    all of that whitespace is effectively ignored, whereas here:

    name = value1 value2
                 ^
    

    this is kept.


    To answer your question, not all of this is fully documented so some of this behavior is by observation, but most of it is, on the git-config documentation page:

    The syntax is fairly flexible and permissive; whitespaces are mostly ignored. The # and ; characters begin comments to the end of line, blank lines are ignored.

    and

    Leading whitespaces after name =, the remainder of the line after the first comment character # or ;, and trailing whitespaces of the line are discarded unless they are enclosed in double quotes. Internal whitespaces within the value are retained verbatim.