You find these rules in more depth explained in the official docs.
- foo/ matches any folder foo (in any folder inside your git worktree), but no file foo or foo.txt
- foo matches any folder foo and file foo (in any folder inside your git worktree) but not files that contain the string, like foo.txt
- * matches anything except / and ? (in any folder inside your git worktree). So foo* would match foo.txt and *.txt would also match foo.txt
- abc/foo matches /abc/foo but not /bar/abc/foo. Whenever you have a string that contains /(except trailing slash) its always considered from the level of the `.gitignore` file. There is no difference between abc/foo and /abc/foo
- **/abc/foo matches /abc/foo and /bar/abc/foo. It matches any path ending with abc/foo in it.
- abc/** matches all files and folders with infinite depth. abc/* matches all files and folders in the directory abc.
- abc/**/*.json matches all json files in the folder abc or its subfolders. abc/*.json would only match all files in the folder abcbut not in its subfolders.
- The prefix ! negates the pattern. Any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded.
Note that empty folders are not tracked by git.
Given the following folder structure.
Can you guess what is tracked when using the following .gitignore files?
Lets consider another scenario
How to ignore all folders bar?Show Answer
How to ignore all json files in folder A?Show Answer