.gitignore: Check Rule Excluding Files
Sometimes, we might find ourselves fighting .gitignore
rules while adding folders or files to git index. For such occasions, there is a git command that to help us figure out which rules is causing a file or folder to be ignored.
git check-ignore -v <path_to_file_to_check>
If you are working with multiple files. The -n / –non-matching parameter will help display both included and excluded paths. For the included, associated rules will be displayed.
❯ git check-ignore -v -n *
.gitignore:1:a.bin a.bin
:: a.txt
:: b.txt
:: c.txt
:: d.txt
If you are interested to know about the history of check-ignore command. Check out this Stackoverflow page