Skip to content

Instantly share code, notes, and snippets.

@YakDriver
Last active March 15, 2023 12:15
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save YakDriver/95f7d165ff5030c000a813d974a170dc to your computer and use it in GitHub Desktop.
Save YakDriver/95f7d165ff5030c000a813d974a170dc to your computer and use it in GitHub Desktop.
Re-sync a fork with the upstream repo

First, you want to make sure that your upstream is setup. Here origin is your fork and upstream is the forked repo.

$ git remote -v
origin	https://github.com/YakDriver/watchmaker.git (fetch)
origin	https://github.com/YakDriver/watchmaker.git (push)
upstream	https://github.com/plus3it/watchmaker.git (fetch)
upstream	https://github.com/plus3it/watchmaker.git (push)

If you don't have the main repo, then add the remote (i.e., upstream) repo. You can call it anything but convention says that the repo you own (i.e., your fork) is the origin while the main repo (i.e., the one you want to submit a PR to) is upstream.

$ git remote add upstream https://github.com/user/repo.git

Now with upstream setup, you can sync the two when changes happen on the upstream repo that you want to bring back to your repo.

NOTE: There are two ways to do this. One is a hard reset. You will lose all changes to origin. This might be good if you messed up your fork and want to have a reset. I've also found this handy when my origin gets hosed up.

The HARD Reset

develop here is the name of the branch you want to reset. The branch must exist in both origin and upstream.

$ git fetch --all
$ git checkout develop
$ git reset --hard upstream/develop
$ git push -f

The SOFT Reset

This will apply any commits that have been applied to upstream and apply them to your repo.

develop is the name of the branch you want to reset. The branch must exist in both origin and upstream.

$ git checkout develop
$ git pull upstream develop
$ git push
@i-Sa3ed
Copy link

i-Sa3ed commented Mar 15, 2023

I'd like to thank you a lot..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment