Check
non-trivial gitignore patterns using git check-ignore
Today I ran into an issue where I tried creating a new
bin/ dir in a git repo, and trying to add the
files within to a new commit, but was greeted by:
$ git add bin/README.md
The following paths are ignored by one of your .gitignore files:
bin
hint: Use -f if you really want to add them.
hint: Turn this message off by running
hint: "git config advice.addIgnoredFile false"Confused, I ran a simple grep on the project’s
.gitignore:
$ grep bin .gitignorewhich yielded nothing. I was pretty sure I didn’t have that pattern set in my global gitignore, either.
A quick internet search turned up a git util that is new to me:
https://git-scm.com/docs/git-check-ignore
Using this command, I was able to trace the exact line responsible:
git check-ignore -v bin
.gitignore:123:[Bb]in binOhhhhh, oops. Well, that makes sense. Neat! This could’ve been solved
with a more sophisticated grep pattern, but who has time
for that?
Tags: git
Created: 2021-03-19T09:30:00Z · Updated: 2021-03-19T19:40:30Z