Sub topic 12
Forks, pull request refs, caches, and old clones
This chapter assumes you have already rotated the leaked credential, rewritten history with git filter-repo, verified the result, and force-pushed. You should be comfortable with Git remotes and refs and know that commits are identified by hashes. The rewrite fixed your repository. It did not fix every copy of the old history, and this chapter covers where those copies live and what you can do about each one.
Why a force-push does not erase old commits
A rewrite creates new commits with new hashes. The old commits are not changed. They become unreachable from your branches and tags, but they still exist as objects wherever they were copied or stored.
Anyone who knows an old commit hash, or who has a copy of the old objects, can still read the secret. This is the reason the first step of the whole process is to rotate the credential. Everything in this chapter is cleanup that reduces exposure. None of it replaces rotation.
Where old history can survive
The table lists the common places and who controls each one.
| Location | Why the old commits remain | Who can clean it |
|---|---|---|
| Forks | A fork is an independent copy with its own objects and refs | The fork owner, or the host's support team |
| Pull request refs | The host keeps read-only refs such as `refs/pull/N/head` pointing at old commits | The host's support team |
| Host caches and unreachable objects | The server keeps objects until garbage collection runs, and may serve them by hash | The host's support team |
| Local clones | Each clone has its own copy of every object | Each person who cloned |
| Backups, CI caches, and mirrors | They store snapshots or copies of the repository | Whoever runs those systems |
| Third-party copies | Search indexes, code scanners, and archives may have copied the content | Often nobody, which is why rotation matters |
Forks
A fork on a hosting platform is a separate repository. Your force-push does not reach it. If someone forked before the rewrite, the fork still holds every old commit, including the one with the secret.
What you can do:
- List the forks. Most hosts show a fork count and a list of forks on the repository page or through an API.
- Contact each fork owner. Ask them to delete the fork, or to re-fork from the cleaned repository after you have rewritten history.
- If the fork owner is unresponsive, contact the hosting platform's support. Many platforms have a process for removing sensitive data and can act on forks in the same network.
- For a private repository, check who has access. A private repository's forks are usually limited to users you already granted access to, which makes the list shorter.
A fork of a public repository can be hard to track once the repository has been public for a while. This is another reason to treat the secret as compromised.
Pull request refs
Hosting platforms store pull request branches under special refs, for example refs/pull/42/head on GitHub. These are read-only, and you cannot update or delete them with a normal push. If a pull request contained the secret, the old commits stay reachable through that ref even after you force-push your branches.
You can see which refs the server advertises:
git ls-remote originLook for lines that start with refs/pull/ or similar. A normal git push --force --all pushes only branches. It does not touch these refs, and the host usually rejects attempts to push to them.
Options for dealing with them:
- Ask the host's support to remove the cached pull request refs and run garbage collection on the server. Provide the old commit hashes, the repository name, and a description of the secret type. Do not paste the secret itself into a ticket.
- If the pull request itself holds the secret in its description, comments, or diffs, edit or delete that content in the web interface. The diff view renders from the old commits, so deleting the comment text does not remove the commit content.
- If the repository is small and the history is not needed, a more drastic option is to delete the repository and create a new one from the cleaned clone. This removes the pull request refs, issues, and other metadata, so use it only if you accept that loss.
Server-side caches and unreachable objects
Git hosts store objects in repositories that are periodically garbage collected. After your force-push, the old commits are unreachable from any branch or tag, but the server may keep them for days or weeks. While they remain, a person with the full commit hash can often view them through a URL such as /commit/<hash>.
Hosts also cache rendered pages, search results, and API responses. You cannot clear those yourself.
What you control is limited:
- Delete the old commit's visibility by asking support to run garbage collection and purge cached views.
- Check search results on the host and on external search engines for the secret string. Request removal where you can.
- Review any CI system that cloned the repository. Runners often keep a workspace or cache with the full history. Clear those caches and rebuild from the cleaned repository.
Old local clones
Every collaborator who cloned before the rewrite has the old objects on disk. This is also the danger for your own machine. Your original working copy, before you made the fresh clone, still contains the secret.
Two risks follow from old clones:
- The old history can be pushed back. If a collaborator runs
git pushor merges an old branch into the new history, the old commits return to the remote, along with the secret. - The secret stays readable on disk, including in the reflog, which records where branches pointed before.
Tell collaborators to re-clone instead of pulling. A pull would try to merge the old history with the new, which creates a mess of duplicated commits and may reintroduce the secret. The next chapter covers what to say to your team in detail.
If someone needs to keep local work, they should save the changes as patches, re-clone, and apply them to the cleaned history:
git format-patch origin/main..my-feature -o ../patches
cd ..
git clone [email protected]:org/repo.git repo-new
cd repo-new
git switch -c my-feature
git am ../patches/*.patchThe format-patch range uses origin/main, which is the remote-tracking ref in the old clone, so run it before deleting that clone. Patches contain the diffs of each commit, so check them for the secret before you apply them. A patch made from a commit that contained the secret carries the secret with it.
Cleaning a local clone you plan to keep
If you must keep an old clone, you can expire the reflog and prune unreachable objects. This is only meaningful after the references to old commits are gone, for example after you point the branches at the rewritten history.
git reflog expire --expire=now --all
git gc --prune=now --aggressiveThese commands delete the safety net that lets you recover from mistakes. Run them only when you are sure the rewritten history is correct and you have a backup you do not mind losing the secret from. For most people, deleting the old clone and re-cloning is simpler and safer.
Backups, mirrors, and CI
Look beyond Git itself. Ask where else the repository content goes:
- Backup systems that snapshot the host or the server.
- Mirrors that copy the repository to another host.
- CI caches and build artifacts that include source files or environment dumps.
- Container images built from a checkout that included the secret file.
- Package registries, if you published a package built from the leaked files.
- Chat or ticket systems where someone pasted the secret or a diff.
For each, decide whether to purge it, expire it, or accept it because the credential has been rotated. Write down the decision so that you can show later that you checked.
A practical checklist
- Confirm the credential is revoked or rotated, and that the new one is stored outside the repository.
- List forks and ask owners to delete or replace them.
- Run
git ls-remote originand note any pull request refs that point at old commits. - Contact the hosting platform's support with the repository, old commit hashes, and the secret type.
- Clear CI caches and rebuild.
- Tell collaborators to re-clone, and have everyone delete old local copies.
- Search the host and public search engines for the secret string.
- Monitor the service the credential belonged to for use of the old secret. Unexpected activity after rotation shows that someone found a copy and tried it.
Common mistakes
- Treating the force-push as the end of the job. The remaining copies are outside your repository.
- Pasting the secret into a support ticket or chat message while asking for help. Use commit hashes and file paths.
- Pulling instead of re-cloning, which can merge old commits back in.
- Deleting a fork without checking whether the owner already cloned it.
- Skipping rotation because "nobody could have seen it".
Exercise
After you force-push a rewritten history, a pull request that touched the leaked file still shows the old commit with the secret. Why does this happen, and what can you do about it?
Show answer
The host keeps pull request refs such as refs/pull/N/head as read-only refs pointing at the old commits, and a normal force-push of branches does not update them. You cannot delete them yourself, so contact the hosting platform's support with the repository name and old commit hashes, without pasting the secret, and ask them to remove the refs and run garbage collection. Because the old commits may stay readable until then, the credential must already be rotated.
Exercise
A teammate has an old clone with unpushed work and runs git pull after your force-push. What can go wrong, and what should they do instead?
Show answer
The pull tries to merge the old history with the rewritten history, which duplicates commits and can push the old commits, with the secret, back to the remote. Instead they should save their work as patches with git format-patch, make a fresh clone of the cleaned repository, apply the patches with git am after checking them for the secret, and delete the old clone.