Check Which Pattern a File Matches in a .gitignore File
Topic: Git
Published on Updated
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