Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forward slash in Gitignore files

Tags:

git

gitignore

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?

like image 993
Saurabh Kumar Avatar asked Jul 10 '18 11:07

Saurabh Kumar


2 Answers

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
like image 92
Nico Albers Avatar answered Oct 16 '22 09:10

Nico Albers


It's because Git was originally written to run on Linux, and the / is the path separator for Linux.

The forward-slash paths will work fine in Windows. In fact, in many places in Windows, if you type your paths with forward slashes, it'll correct them for you automatically.

like image 40
Ryan Lundy Avatar answered Oct 16 '22 08:10

Ryan Lundy