Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save valera-rozuvan/c694733e6e4c5b5975b11b11e9d3ea7f to your computer and use it in GitHub Desktop.
Save valera-rozuvan/c694733e6e4c5b5975b11b11e9d3ea7f to your computer and use it in GitHub Desktop.
howto update local and fork git repos with latest from upstream

howto update local and fork git repos with latest from upstream

Suppose your fork remote is named fork, and your upstream remote is named original. You are working on the branch main.

Make sure that you are on branch main, and that you have no local changes. I.e. running:

git status

should produce something like:

On branch main
Your branch is up to date with 'fork/main'.

Now, what you want to do is fetch changes from upstream:

git fetch --prune original
git reset --hard original/main
git clean -f -d

This makes your local repo exactly like your remote repo. Then you can update your fork with latest from upstream:

git push --force fork main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment