Search code examples
gitgitignore

Forward slash in Gitignore files


I came across a very weird thing about gitignore files that they happen to use forward slash for denoting a particular directory

Project/module1/cppfiles

Rather than the usual backslash normally used in command prompt for denoting a particular directory.

Project\module1\cppfiles

Is this completely syntactical or it has some reason behind it?


Solution

  • I soonly found a windows documentation, compare here, which tells:

    Windows users: All file paths in the .gitignore file use a forward slash separator and not a backslash.
    

    git uses forward slashes in the .gitignore for compatibility with unix syntax, where you separate folders by forward and not by backward slash. This probably is related to two things:

    1. git mostly is running on linux servers, so this must not be catched on server side, only on client side
    2. (probably) a lot of the people using git are using unixoid systems, therefore only a few are using backward slashes - only few people have to change behaviour to work together with all others