To remove secrets from git history before licensing or selling a codebase, scan every commit on every branch with gitleaks or TruffleHog, revoke and rotate each credential you find, and then rewrite the history with git filter-repo --sensitive-data-removal. Order matters: rotation is what makes a leaked key harmless, and the rewrite only cleans up the copy. A code buyer receives the full history, so a key deleted from the codebase years ago still sits in every old commit unless you act.
Why does a code buyer get your old secrets?
Because history is what they are buying. AI developers pay for private code with its commits, pull requests, reviews and linked issues, since that history can be turned into training tasks of the form "here is a bug report, produce the fix and pass the tests". A final snapshot is worth much less, as our guide to selling source code for AI training explains.
That history carries everything ever committed. git rm removes a file from the next commit, not from the ones before it.
Turing's Project Lazarus publishes its intake steps, which show when history leaves your hands. As of November 2026:
| Stage | Timing | What Turing says it checks |
|---|---|---|
| Initial screening | Same day | 50K+ lines of code, English comments and issues, the app runs, a Dockerfile that builds and runs |
| Evaluation script | About 30 minutes, run by you | Human-authored PRs, valid dates, closed linked issues, test files, commit spread |
| Turing review | 1 business day | Script output and your data inventory |
| Deep technical review | 4 to 6 business days | You grant temporary repo access; PRs that solve one issue, Dockerization, SWE-bench compatibility, tests, no LLM-written code |
| Decision | Varies | Final offer and payment |
The published list does not name a secrets scan. It doesn't need to: at stage 4 an outside team can read every commit. Clean the history before that point, not after.
How do you find secrets in git history?
Run a scanner over all refs, not just the current branch. Both main open-source options read the full commit history.
gitleaks (MIT) runs git log -p under the hood. Since v8.19.0 the detect command is deprecated in favor of git:
# Every commit on every branch, with findings printed
gitleaks git -v --log-opts="--all" .
# Save a JSON report; --redact keeps secret values out of the terminal
gitleaks git --log-opts="--all" --redact --report-path gitleaks-report.json .
TruffleHog (AGPL-3.0) adds verification: for each candidate it calls the provider's API to check whether the credential still works, and labels results verified, unverified or unknown.
# Local repo, verified and unknown results only
trufflehog git file://. --results=verified,unknown
# Also scan GitHub issue and PR comments, which buyers receive with linked issues
trufflehog github --repo=https://github.com/YOUR-ORG/YOUR-REPO --issue-comments --pr-comments
Verification sends each found credential to the service it belongs to. That is the point, but know it before you run it, and add --no-verification if you would rather not.
The second command matters for code deals specifically. Buyers want issues linked to commits, and people paste tokens into issue threads as often as into code.
Should you rotate or rewrite first?
Rotate first. GitHub's guide to removing sensitive data from a repository says the first step for any leaked password, token or credential is to revoke or rotate it, and that for your own repository this may be enough on its own.
For a copy that will leave the company, we still recommend removing them. A revoked key in a delivered repo will light up the buyer's scanner, and the same commits often reveal internal hostnames, database names and vendor accounts. Some material can't be rotated at all: customer records in test fixtures, database dumps, signing keys that shipped in old releases.
How do you remove secrets with git-filter-repo?
Use a fresh clone, run git-filter-repo with --sensitive-data-removal (version 2.47 or later), then verify. The tool refuses to run on a repo that doesn't look like a fresh clone, as a safety check.
git clone https://github.com/YOUR-ORG/YOUR-REPO.git repo-clean
cd repo-clean
# Delete whole files from every commit (add a --path for each old name if it was moved)
git filter-repo --sensitive-data-removal --invert-paths --path config/secrets.yml --path .env
# Replace leaked strings wherever they appear in text files
git filter-repo --sensitive-data-removal --replace-text ../leaked.txt
The expressions file takes one entry per line. Plain lines are literal, regex: and glob: prefixes are supported, and ==> sets the replacement (the default is ***REMOVED***):
PASTE_THE_LEAKED_VALUE_HERE
regex:postgres://[^@\s]+@==>postgres://REDACTED@
Running several passes in the same clone is supported. If you don't yet know what to remove, git filter-repo --analyze writes a report of paths and blob sizes without changing the repo, which helps spot database dumps and stray files. After the rewrite, check that nothing survived:
git log --all --name-status -- config/secrets.yml .env
git log -S"PASTE_THE_LEAKED_VALUE_HERE" --all -p --
gitleaks git -v --log-opts="--all" .
Two output files are worth keeping. .git/filter-repo/commit-map maps every old commit hash to its new one, which lets you fix issue-tracker links that cite commit hashes, so the linkage a buyer values survives. .git/filter-repo/first-changed-commits lists where the rewrite began.
Rewrite the original, or only the copy you deliver?
You have two options, and the second is often enough for a licensing deal.
-
Rewrite the original and force-push (
git push --force --mirror origin). Everyone must re-clone or carefully clean up, or a singlegit pullandgit pushbrings the data back. GitHub lists the side effects: new commit hashes, broken diffs on closed pull requests, removed commit signatures, and protected branches that need unlocking. Cached views andrefs/pull/*refs need a GitHub Support request. - Rewrite only a delivery copy. Push the cleaned clone to a new, separate repository and give the buyer access to that. Your team keeps working undisturbed, and the credentials in the original are already rotated.
Option 2 only works if the buyer never gets access to the original, so set that up before stage 4 of any intake process.
How do you keep new secrets out?
Block them at commit and push time, because cleaning history is slow and disruptive. Add gitleaks as a pre-commit hook or CI step. If the history is large and already messy, detect-secrets records a baseline of existing findings so only new ones fail. On GitHub, push protection rejects pushes that contain supported secret types. Our guide to keeping company data sellable covers the habits that protect the rest of the record, such as keeping full history rather than squashed snapshots.
Common questions
Does rewriting history lower the value of the code?
It shouldn't, if done carefully. Commits, messages, authors, dates and diffs stay; only the removed files and strings change, along with the hashes. Use the commit map to update links from issues to commits. Avoid squashing or truncating history to save effort, since history is what buyers pay for.
What else should I look for besides API keys?
Customer data in test fixtures and seed files, database dumps, .env files, private keys, internal URLs, and code you don't own. Our source code guide lists contractor code without an IP assignment, client work and vendored libraries as the usual ownership gaps. A license scanner such as ScanCode helps with the last one.
Do I need to do this if the buyer signs an NDA?
Yes. An NDA limits what the buyer may do with what it sees; it does not make a live credential safe. Rotation protects you regardless of the paperwork, and removal keeps the delivered copy clean for everyone who later handles it.
Can a buyer tell that history was rewritten?
Usually, if it compares against an earlier copy, because hashes change from the first rewritten commit onward. That is normal and worth disclosing. Say what you removed (credentials and specific files) and keep the gitleaks report showing a clean result.
If you have a codebase and want a rough sense of what its history is worth before you start, our free estimate takes six questions and needs no repo access.
Origin Data Partners is an independent data partner that helps companies get their data bought. We are independent of the companies named here, and a buyer may pay Origin when a deal closes.
Top comments (0)