Debugging .gitignore

Photo by Austin Ban via Unsplash

Here are my favorite (most frequently used) resources for debugging .gitignore files:

I found this resource on a random hunch that there would be some way to audit or trace back ignored files to see which rule in particular was causing the file to be ignored. After searching for a while, I stumbled across this blog post by Doug Rathbone that does a great job explaining how to do this:

When .gitignore stops being your friend – Debugging missing Git repository files

Using the command below, you can find the exact line of your .gitignore file that is causing the file to be ignored.

git check-ignore –n –v path/to/your/ignored/file

Before I discovered this command, I had been troubleshooting my .gitignore file by deleting chunks of the file and saving, then looking at Sourcetree to see what files popped up. It was my way of narrowing down on what section caused the file to be ignored. Now that I have this, I can find the line number for the rule with just this one command!

Ignoring a Folder But Tracking Its Subdirectories

This StackOverflow answer is helpful if you’re ignoring directories like wp-content, but want to track your theme directory. I tend to forget this part, “The trailing /* is significant.

How to Check Ignored Files in Sourcetree

Another important thing to remember is that even if you mess up your .gitignore file, your repository can still be fixed.

View Ignored Files in Sourcetree