Clean up your Git repo fork and update it from upstream aka start clean

Peter Jausovec
1 min readMay 3, 2023

This is more of a note for myself because I search for this occasionally.

Here’s the scenario — you fork a Git repo, clone the fork, and set up two remotes:

  • origin — points to your forked repository
  • upstream — points to the source repo (i.e., the repo you created the fork from)

At some point, you might end up in a state where your local fork is not clean anymore (perhaps you committed something, experimented, etc.), and the upstream repo has a bunch of changes you want to bring to your fork.

Assuming you want to discard changes in your fork and “start fresh” from upstream, you can do it like this:

git fetch upstream
git checkout main
git reset --hard upstream/main
git push origin main --force

Done! Your fork (origin) is now up-to-date with the upstream repo.

--

--