Being ignored? Find out why with git check-ignore

Have you got files being ignored in source control and you don't know why? Git's got your back. Here I demonstrate git's secret weapon: check-ignore
Being ignored? Find out why with git check-ignore
July 2025

I'm the first to admit that my git knowledge isn't the greatest. Sure, I can get by - do what I need to do - but I'm by no means an expert. I'm hoping that by doing a few of these posts on my favourite git features it will inspire me to learn more!

Situation

I had picked up a project from someone else, and wasn't too familiar with the code base. I needed to add a file to the repository - an executable file that was needed as a dependency to run the code locally.

I added it to the repository but it didn't show up in the pending changes section of my editor.

Instantly I recognised that this file was being ignored with the .gitignore file - it was just a case of finding the rule! This particular repository was home to a number of different sub-projects in different languages. Each of these directories had a different .gitignore, and there was one at the top level. I started scratching round in these files, trying to find the rule causing the exclusion. I thought that there must be a better way to find it. On a whim, I did a quick google search and sure enough I found a solution!

Solution

The check-ignore feature of git can help us here. Simply, I ran the following in my repository:

git check-ignore -v bin/my-ignored-file

And this tells my exactly which rule in which gitignore file is causing me the problem:

my-project/.gitignore:99:bin/ "bin/my-ignored-file"

Explanation

Let's unpack what all this means:

  • my-project/.gitignore is the location of the .gitignore containing the offending rule.
  • :99:bin/ this means that on line 99 of the .ignore file, there is a bin/ rule, and it's this one that's causing the problem.
  • bin/my-ignored-file the missing file.

Then you can make any adjustments you like. For me, I wanted to keep the bin/ rule, but include one the one dependency. So I added the following rule to my .gitignore:

!bin/my-ignored-file

And then I could commit my file

Happy committing!

Read next

VW Golf dashboard with a start-stop system failure warning light illuminated
Apr 2026

Troubleshooting the start-stop system failure on my VW Golf - Part 1

Usually I write these blog posts after I've fixed the problem - but this time I'm writing it as I go. Join me as I gather information and build a list of ideas.

Read post →
Abstract illustration of a fast simple hosting setup
Mar 2026

How I manage content on this website

Learn how this blog site is put together - with minimal dependencies and bloat

Read post →
A smartphone camera lens surrounded by abstract binary data streams and TIFF file grid patterns
Mar 2026

Generating TIFF files on an Android device

No library was up to the job, so I read the spec and wrote my own TIFF encoder.

Read post →