What is difference between "git check-ignore *" and "git ls-files --other --ignored --exclude-standard"?

Viewed 326

I'm trying to check files that are ignored by git, and I found 2 commands show same result.

which are

  1. git check-ignore *

  2. git ls-files --others --ignored --exclude-standard

It seems different approach, but would it show same result in any condition?

1 Answers

Although not specifically documented, the difference is that git check-ignore <pathname> doesn't recurse into subdirectories1, while git ls-files --others does.

Let's say that your working directory looks like this:

.
|-- ignored-file
|-- bin
|   |-- another-ignored-file

While being at the root of the working directory, if you run:

git check-ignore *

You'll get just ignored-file. If you run:

git ls-files --others --ignored --exclude-standard

You'll get:

ignored-filed
bin/another-ignored-file

Now, if you were to run both commands in the bin directory, you'll get the same output.


  1. It's actually kind of surprising that git check-ignore accepts wildcards at all, since the documentation calls the argument pathname and not pathspec. Update: as @LeGEC pointed out in the comments, the shell is interpreting the pathname, hence the support for wildcards.
Related