Git Checking if a file is ignored


The git check-ignore command reports on files ignored by Git.

You can pass filenames on the command line, and git check-ignore will list the filenames that are ignored. For example:

$ cat .gitignore
$ git check-ignore example.o

Here, only *.o files are defined in .gitignore, so is not listed in the output of git check-ignore.

If you want to see line of which .gitignore is responsible for ignoring a file, add -v to the git check-ignore command:

$ git check-ignore -v example.o
.gitignore:1:*.o        example.o

From Git 1.7.6 onwards you can also use git status --ignored in order to see ignored files. You can find more info on this in the official documentation or in Finding files ignored by .gitignore.