Deleting a leaked secret from your GitHub repository does not delete it from forked repositories, and deleted secrets often stay reachable for months after the original commit is gone. For a security team that has just scrubbed an AWS key or database password from its main branch, that is the uncomfortable part. This article explains how forks keep deleted data, why history rewriting is not enough, and what to do in the first hours after you find an exposed credential in a repository that has been forked.
How Fork Networks Actually Store Your Data
On GitHub, a fork is not a full, independent copy in the way most developers picture it. The original repository and all its forks belong to a single fork network that shares one underlying object store. Commits, trees and blobs are stored once and referenced by every repository in the network.
This matters because “deleting” a commit in Git only removes the references to it. The object stays in storage until garbage collection runs, and in a shared fork network GitHub does not garbage-collect objects that any member might still need. In practice that means much of the network’s history is kept for as long as the network exists.
In July 2024, Truffle Security published research describing what they called Cross Fork Object Reference (CFOR). They showed three scenarios. Commits pushed to a fork could be read through the upstream repository after the fork was deleted. Commits in a deleted upstream repository could be read through any surviving fork. Commits made in a private repository could become reachable through public forks once the repository went public. GitHub’s position was that this is intended behaviour and is documented. That leaves the problem with the people who own the secrets.
Why Deleted Secrets in Forked Repositories Are Easy to Find
To reach a commit through a fork, an attacker needs its SHA-1 hash. That sounds like protection until you remember that GitHub accepts short SHAs. A four-character prefix has only 65,536 combinations, which a script can brute-force against the web interface in a short time.
Hashes also leak in other ways. Pull request pages, issue comments, CI logs and the public GitHub Events API all reference commit SHAs. In 2025, researchers showed that force-push events in the public event archive point to “dangling” commits. They mined those commits for live credentials and collected bug bounty payouts on the results. A force-push that a developer thinks of as a cleanup becomes a pointer to the exact commit someone wanted gone.
Common myth: “If we rewrite history with git filter-repo and force-push, the secret is gone.” It is gone from your branch. It is not gone from the 40 forks created last year, from contributors’ local clones, from GitHub’s cached commit views, or from the object store the fork network shares. History rewriting is hygiene, not remediation.
A Realistic Scenario
A platform engineer at a mid-sized SaaS company commits a `.env` file to a public SDK repository on a Friday afternoon. It contains a Stripe restricted key and a PostgreSQL connection string. A secret scanner flags it on Monday morning. By then the repository has 12 forks, three of them created over the weekend by accounts with no other activity.
The engineer runs BFG Repo-Cleaner, force-pushes and closes the ticket. Two weeks later the database shows logins from an unfamiliar ASN. The key was never rotated. The cleaned repository looked fine, but the original commit was still readable through any of the forks. An experienced incident responder would have treated the 72-hour exposure window as a confirmed leak from the first minute and started with rotation, not cleanup.
Response Steps When a Secret Lands in a Forked Repository
An experienced practitioner works in this order, because the order is what limits damage:
1. Revoke and rotate immediately. Assume the secret is compromised. Issue a new key, deploy it, then revoke the old one. Our guide on rotating credentials after a leak alert covers sequencing so you avoid outages.
2. Check access logs for the exposure window. Look at AWS CloudTrail, Stripe dashboard logs and database audit logs from the commit timestamp onward, not from detection.
3. Map the fork network. The Forks tab and `gh api repos/OWNER/REPO/forks –paginate` list the visible forks. Record each fork’s creation date against the leak timestamp.
4. Rewrite history and contact GitHub Support. Use git filter-repo, then ask Support to remove cached views and pull request references. Under its own documentation, GitHub cannot delete forks owned by other users.
5. Scan the full history, not just HEAD. Other secrets often sit in the same commit range. Scanning past commits is covered in detail in Git history scanning for secrets you already deleted.
Common Mistakes Teams Make
The most frequent mistake is treating cleanup as the fix. Teams spend hours on BFG and force-pushes and minutes on rotation. That has the priorities the wrong way round. A rotated secret sitting in a fork is a harmless string. A non-rotated secret removed from main is still a live credential.
The second is scanning only the default branch. Gitleaks and TruffleHog both scan full history by default when pointed at a cloned repository. Some CI integrations, though, are configured to scan only the diff of the current push. A secret introduced on a feature branch that was later deleted will never show up in those scans. The comparison of secrets scanning tools covers those blind spots by tool.
The third is making an internal repository public without auditing its past. Companies open-source an internal tool, scan the current tree, find nothing and flip the visibility switch. Five years of history goes public with it, including the API token someone hardcoded in 2021 and “removed” a week later. If the repository was ever forked privately, that history may be reachable even after a rewrite.
Edge Cases and Exceptions
Not every environment behaves like public github.com. On GitHub Enterprise Server or a self-managed GitLab instance, administrators can run garbage collection and purge unreachable objects themselves. That makes real deletion possible, provided no one has cloned the data off the instance. GitLab’s fork object pools are different from GitHub’s fork networks, so check your version’s documentation before assuming either behaviour.
Private repositories in an organization are lower risk but not risk-free. Private forks inherit the parent’s history, and offboarded contractors may still hold forks or clones. Teams under 10 people often skip fork audits entirely. Even so, a single contributor’s personal fork of a work repository is a common way secrets end up outside company control.
In regulated sectors such as finance or healthcare, an exposed credential that guarded personal data can trigger GDPR or HIPAA notification obligations, however quickly you cleaned the repository. Document the timeline from the start.
FAQ
Can GitHub delete a secret from all forks of my repository?
No. GitHub Support can remove cached views and references in pull requests on your repository, but forks owned by other accounts are outside your control. Rotation is the only reliable fix.
Does making a repository private protect the secrets in its history?
Not fully. When a public repository becomes private, its existing public forks stay public in a separate network and keep the full history up to that point.
How quickly are secrets in public commits exploited?
Automated scanners watch the public GitHub event stream constantly. Exposed cloud keys are often tested within minutes, so any public push should be treated as an immediate compromise.
Final Takeaway
Forks turn every commit into a semi-permanent record. History rewriting, repository deletion and visibility changes are all useful, but none of them reliably removes data from a fork network. Rotate first, investigate logs from the commit timestamp, then clean up. Add push protection and pre-commit hooks so the next secret never reaches the object store at all.
