I had a very confounding experience recently that dragged on for several days because I didn’t have the time to investigate it. I was working on a new project and adding files as I would normally, when I noticed that every single file I was adding was automatically being ignored by git. I checked my local
.gitignore and could not find a culprit 🤔.
I worked around it by manually force adding everything to source control, but clearly not a long term solution.
Turns out I have a top level global git ignore file on my work machine that I was not aware of 😮. I never even considered to look for this. It could be located in a different place for you, but here is my path:
C:\Users\<Username>\OneDrive – <Company> Corporation\Documents\gitignore_global.txt
This really threw me for a loop, but made sense because the only thing that stuck out to me as a possibility of tripping up a
.gitignore rule was the word “Lib” in my project name. For example:
Amazingly enough after looking inside of the file there it was
*.lib was not permitted.
Hunting down the problem
I did my normal troubleshooting steps because it’s not like I haven’t experienced this before, but the old trick of “Remove your
.gitignore file temporarily” didn’t work which just added to the confusion 😕. Luckily there is a tool for this exact issue.
git check-ignore to the rescue! I didn’t even know this was a thing (or I forgot because it’s been that long).
The fastest way to use this is to do the following:
- Identify ONE file that is experiencing an unwanted ignore.
- Get the full file path for that file.
- Run this git command:
git check-ignore C:\dev\myproject\file-I-want-in-source-control.txt, obviously replace the example path.
- This will give you output that indicates WHICH
.gitignoreis ignoring your file and WHY. It will tell you which rule tripped.
This was very helpful to hunt down my very not obvious ignore issue. Showed me that I had a global file I wasn’t aware of and now I have a new tool to help me track these issues down immediately in the future.