Safeguard
Security Guides•

Do secrets in old repo history follow you into the monorepo?

Yes: importing history imports any secret that was ever committed. Scan before the merge, rotate what you find, and rewrite only if rotation is not enough.

Safeguard Security Team
3 min read

Yes. If you import a repository with its history, every secret ever committed to it comes along, including ones deleted years ago. A monorepo also widens who can read them. Scan the old history before the merge, rotate anything live, and treat history rewriting as a cleanup step, not a fix.

Why the merge makes it worse

In a separate repo, an old leaked key might be visible to ten people. In a monorepo, the same history is visible to everyone with read access to the whole repository, and it is cloned onto many more laptops and CI runners. GitHub's guidance notes that any user with write access to a repository has read access to all secrets configured in it, which is a reminder that repo-level access is the unit of trust. Merging repos merges their trust boundaries.

Steps before you import

  1. Scan the full history of each source repo, not only the current files. Use a history-aware secret detection tool of your choice. The current checkout tells you nothing about commit 400 of 9,000.
  2. Triage by liveness. A key that no longer works is a finding to note, not an emergency. A key that still authenticates needs action today.
  3. Rotate every live credential. Rotation is the control that works. Rewriting history does not recall copies that already exist in clones and forks.
  4. Decide whether to rewrite. git filter-repo can replace or remove sensitive text, using a file of expressions passed to its replace-text option, with ***REMOVED*** as the default replacement. Use it when you want the monorepo to start clean, and remember the tool writes new commits and deletes the originals in that clone.
  5. Import the cleaned clone, not the original.
  6. Keep a record: which repos were scanned, what was found, what was rotated and when. Auditors and customers ask for that trail.

What rewriting does not do

Rewriting a clone does not change the old remote. Anyone with an old clone still has the secret. Pull requests and forks on a hosting platform may hold references too. This is why the order matters: rotate first, rewrite second. For the deeper argument see secrets in git history: rotate, do not rewrite.

A short decision table

SituationAction
Secret found, still validRotate now, then decide on rewrite
Secret found, already revokedNote it, optional rewrite
Repo has no history worth keepingImport current state only
Large generated files plus secretsFilter both in the same pass

Check the neighbours

The same import can carry other risks: committed .env files, private keys, cloud config. Add the file names to your scan rules. Also check that CI configuration in the old repo does not reference secrets that will no longer exist, which is covered in do GitHub Actions secrets move when you consolidate repositories.

For the merged repository itself, Safeguard's asset discovery and SBOM and dependency scanning show what the new repo contains, and you can try a free scan at gold.safeguard.sh/scan.

Quick check

If I delete the file in a later commit, is the secret gone?

No. The file and its contents remain in earlier commits and are imported with the history.

Is rewriting history enough on its own?

No. Old clones and forks keep the original objects. Rotate the credential first.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.