Debugging the .gitignore file

Kennard • June 19, 2019

git

Ever had a rogue .gitignore causing problems? Here's a quick tip on how to debug something like that.

Run the following command in the root of your project directory.

git check-ignore -v path/to/some/file

The important bit here is the -v flag.

This will result in the following output.

.gitignore:3:some/  path/to/some/file

In this example the output indicates that the .gitignore file in the root of the project is the culprit. It contains some/ on line 3 which causes path/to/some/file to be ignored.

This command can especially be helpful when you have configured a global excludes file in ~/.gitconfig and just can't figure out why a particular file is being ignored.