That’s how sensitive data leaks happen. An API key, a password, a private certificate—pushed without a second thought, buried deep in history, and cloned to the world. You can delete the file, but Git never forgets. Until you tell it to.
Why Git reset alone won’t save you
A simple git reset just changes HEAD. It doesn’t rewrite the history where the secret first appeared. Anyone with a copy, or even access to your remote, can still see the data. Real removal from history needs tools that surgically alter the commit tree.
How to remove sensitive data from Git history
- Identify the exposure
Find the exact file or string, and locate the commit hash. - Use
git filter-repoor BFG Repo-Cleaner
These tools rewrite repository history, deleting the file or replacing secrets wherever they appear. - Force push cleaned history
Usegit push --forceto update the remote. - Invalidate the exposed secret
Change passwords, regenerate API keys, or rotate certificates immediately. - Invalidate old clones
Anyone with an old clone has the secret in plain sight. Notify, revoke, and require fresh clones from the cleaned repository.
Example with git filter-repo