Tips and Tricks: Git Check-Ignore

Have you ever found yourself wondering “why in the world is git ignoring this file!?”

Have you spent countless minutes combing over every line of a .gitignore to try to determine what obscure rule is preventing your file from being committed?

I have something that can help! It’s called

git check-ignore

and it will CHANGE. YOUR. LIFE! (your results may vary)

If you haven’t heard about the

git check-ignore

command, you’re missing out on an underappreciated git command.

I found myself stuck for about 15 minutes one day, trying to figure out why a file wasn’t showing up in git. After banging my head against a wall for so long, I decided to see if there was a better way. I found an article that pointed me at this little command and I it seemed like it wold do the trick. I navigated to the folder that contained the troublemaking file, Settings.config, and typed

git check-ignore -v Settings.config

and it gave me:

.gitignore:51:Source/*.Web/App_Config/Include/zSites/*/**/*.config

I was overjoyed! It told me which gitignore file it was in (there were several on the project), what line to look at, and what the rule was.

If you’d like to read up on it further, check out the official docs: https://git-scm.com/docs/git-check-ignore