It starts when a branch holds a file that should never have been there. Maybe it was a .env file, a private key, or credentials someone committed by mistake. You switch branches, your filesystem changes, and the file is suddenly there. It doesn’t matter that the commit was months old. On checkout, Git rewrites the work tree exactly as it was in that commit. The leak has already happened.
The danger hides in plain sight. Git does not ask for confirmation. There’s no warning that a sensitive file is about to appear locally. That file might be picked up by a local process, indexed by a search service, or pushed to a shared location by a dev tool. Even a short-lived exposure can be enough for automated scanners, backups, or sync jobs to capture the file permanently.
This risk grows the longer sensitive data lives in your repository history. Standard .gitignore rules won’t help with past commits. Removing secrets after the fact is tedious and often incomplete. Common cleanup tools like git filter-branch or git filter-repo help purge data from history, but they can’t stop you or your teammates from checking out an old branch that still contains the leak before the cleanup reaches everyone.