Skip to content
← Blog

A whitelist .gitignore will eat your scripts silently

My infrastructure repository uses a whitelist ignore pattern: everything is ignored by default, and each tracked file is re-included explicitly.

*
!.gitignore
!setup.sh
!deploy.py

The reasoning is sound. The repo lives in a directory that also accumulates credentials, exports, media files and scratch work, and a whitelist means a secret cannot be committed by forgetting to ignore it. Default-deny beats default-allow for anything security-shaped.

The trap

git add on a file that is not whitelisted does nothing. It prints no warning. It exits zero. git status continues to show a clean tree, because as far as git is concerned there is nothing to show — the file is ignored and everything tracked is committed.

So the workflow that fails looks exactly like the workflow that succeeds:

vim smartmon_collector.sh
git add smartmon_collector.sh   # silently does nothing
git commit -m "add SMART collector"   # "nothing to commit, working tree clean"

If you are moving quickly you read that last message as already committed rather than never staged.

What it cost

A custom SMART monitoring collector, written to pull disk health through a RAID controller’s own CLI because the standard path does not work on that hardware. It ran happily on the host for months. It was never in the repository. When the host was rebuilt, the script went with it — and so did every SMART reading it had ever recorded, because the history lived alongside it.

Rewriting the script took an afternoon. The trend data is simply gone.

What I do now

Three things, in order of how much they help:

Verify with git status --short, not with your memory. After adding anything new, look for the A line. If the file is not there, it was not staged. This takes one second and would have caught it.

Add the whitelist entry first. The .gitignore edit is now part of writing a new script, not a follow-up step. A comment above the entry says what the script does and when it was added.

Do not reach for git add -f. Forcing the add works, and it defeats the entire point of the whitelist — the next person, who is me in six months, now has a tracked file with no ignore entry explaining why it is there.

The general version

Any tool that fails by doing nothing is more dangerous than one that fails loudly, because success and failure produce identical output. This is the same class of bug as a backup job that exits zero having copied nothing. If a failure mode is silent, you have to go and look — the tool will not tell you.