Skip to content

Check which pattern a file matches in a .gitignore file

(updated)

Git

Recently I was having issues in a repository where files that were not supposed to be ignored, were being ignored. I stumbled upon Git’s check-ignore command, which will output the pattern in the .gitignore file a specific file matches.

Example Usage

For this example, I’m running the command in a basic Laravel application.

git check-ignore .env

Which will result in this output:

.env

If you want to see a little bit more, you can add -v to get the line number the pattern is on in the .gitignore file:

git check-ignore .env -v

Output:

.gitignore:9:.env	.env

Reference

See more stuff that I've learned

comments

Comments for this post are closed.