Clean up a fork and restart it from the upstream
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Sometimes a fork becomes so cluttered with old branches or stale history that you do not want to merge upstream anymore. You want your fork to look like a fresh copy of the upstream project again. That is essentially a reset operation, and it should be done carefully because it rewrites your fork’s public branch history.
Decide What You Want to Keep
Before resetting anything, decide whether your old work still matters. If the answer is maybe, create a backup branch or tag first. A cleanup is easy. Recovering deleted work after a force push is not.
That gives you a safe restore point before you realign the fork.
Add the Upstream Remote
If the local clone does not already know about the original repository, add it.
Now you can fetch the real source of truth separately from your fork on origin.
Fetch and Reset the Main Branch
Update your local references, then hard-reset your main branch to upstream’s main branch.
If the upstream default branch is master or another name, use that branch instead. After this step, your local main exactly matches upstream.
Force-Push the Reset Fork
If your goal is to restart the fork itself, push the rewritten branch back to your fork.
This is the step that actually changes the remote fork history. Anyone else using your fork will need to resync their local clones after the force push.
Remove Stale Branches
A fork cleanup often also means deleting old local and remote branches that no longer matter.
To delete remote branches on your fork:
Do not delete branches blindly. Make sure they are no longer needed for open pull requests or archived work.
When a Fresh Clone Is Simpler
If the local repository is especially messy, a fresh clone can be easier than deep cleanup.
This avoids carrying over local config and stale branch state you no longer trust.
GitHub-Side Fork Maintenance
Some hosting platforms also provide a way to sync forks through the UI. That can help for ordinary updates. But if your real goal is "make my fork look like upstream again and drop my old branch history," the Git reset and force-push route is more explicit and complete.
Common Pitfalls
- Resetting without a backup branch can destroy work you later realize you needed.
- Force-pushing a shared fork surprises collaborators if you do not communicate first.
- Resetting to the wrong upstream branch is an easy mistake when the default branch name differs.
- Deleting old branches before checking open pull requests can break active work.
- Assuming a merge from upstream is the same as a reset leads to very different history.
Summary
- Add
upstream, fetch it, and reset your main branch to the upstream branch you want. - Create a backup branch before rewriting history if there is any chance you will need the old work.
- Force-push only when you intentionally want the remote fork rewritten.
- Delete stale branches separately after you know they are safe to remove.
- If the local clone is too messy, a fresh clone plus upstream reset is often the simplest path.

