GitHub Docs Removing Sensitive Data from a Repository Git Filter-repo
To scrub leaked secrets, rewrite your commit history and force push clean branches to your remote. The github docs removing sensitive data from a repository git filter repo guide covers this process. Teams often face this problem when developers store static keys in local files. Broad repository write roles also let anyone push unchecked files to shared branches. A single bad commit puts those secrets into every clone of the project. How github docs removing sensitive data from a repository gi
Git Commit Signing (GPG, SSH) + GitHub Actions Security: the complete guide
Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.
To scrub leaked secrets, rewrite your commit history and force push clean branches to your remote. The github docs removing sensitive data from a repository git filter repo guide covers this process. Teams often face this problem when developers store static keys in local files. Broad repository write roles also let anyone push unchecked files to shared branches. A single bad commit puts those secrets into every clone of the project.
How github docs removing sensitive data from a repository git filter repo works
A normal commit that deletes a file does not erase it from history. The old secret stays inside past commit objects in the project folder. Anyone who clones the repository can still read those old commits. To fix this, you must rewrite every commit that touched the file.
The filter tool reads your full history and builds a brand new commit tree. You start by making a fresh mirror clone of your damaged project. Then you tell the tool which file path or text string to strip out. The tool scans every branch and tag in a single pass. It removes the target data and creates new commit hashes from that point on.
Next, you force push the rewritten history back to the remote host. You must also ask support or run host cleanup tasks to purge cached objects. Pull requests and old tags can still hold links to the bad commits. Every person on your team must delete their old local clones right away. If one developer pushes from an old clone, the secret comes right back.
What history rewriting solves and the gap it leaves open
Rewriting commit history cleans up the storage layer of your source control system. It stops new team members from finding old passwords or keys in git logs. It also removes accidentally committed customer data like emails, phone numbers, or card numbers. This step is vital for cleaning up a mess after a leak happens.
Still, scrubbing git history only fixes the static files stored in your repository. Once a secret touches a remote branch, you must treat it as compromised. Bots and forks copy public and private code within seconds of a push. Erasing the file later does not block someone who already copied that key.
Git Commit Signing (GPG, SSH) + GitHub Actions Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
You must revoke and rotate every exposed database password or API key right away. Source control rules only decide who can read or write code in a project. They do not check what live commands or queries do during an active session. Also, if developers need raw credentials on their laptops, leaks will happen again. Cleaning git history fixes past mistakes, but it cannot stop future credential leaks.
Why static keys end up in git history
Developers often need to run quick checks against a live database or service. To do this fast, they copy a connection string into a local script. They test the app on their machine and see that the fix works. Then they stage the whole folder and push the changes to the remote.
Secret scanners can catch known token shapes before or after a git push. Yet custom passwords and internal database strings often slip past those basic text checks. As long as people handle raw passwords on their laptops, git leaks will continue.
Govern statements and responses across databases and APIs
Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.
First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
Does rewriting git history make a leaked password safe to keep using?
No, you must rotate any leaked password or key the moment you find it. Automated bots and user clones can copy the secret before you scrub the history. Rewriting commits only hides the secret from people who clone the repo later.
Why does a deleted file still show up in pull requests on the remote?
Remote hosts keep cached copies of commits linked to open or closed pull requests. Pushing a clean branch does not delete those hidden references on the server. You must close those requests and ask the host to clear cached objects.
What happens if a teammate merges an old local branch after the cleanup?
Merging an old local branch pushes the old commit hashes back to the remote. That action puts the sensitive file right back into the shared project history. Every teammate must delete their local folder and make a fresh clone instead.
Related guides
In this post