Skip to content

Instantly share code, notes, and snippets.

@santisbon
Last active March 16, 2023 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save santisbon/b5e4630bfa3282617eb5888c44ebc236 to your computer and use it in GitHub Desktop.
Save santisbon/b5e4630bfa3282617eb5888c44ebc236 to your computer and use it in GitHub Desktop.
#git #fork

Sync a Fork

Add a reference to the original repo

List the remote for your fork

$ git remote -v

Add a new remote "upstream" that will be synced with the fork

$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

Verify the new upstream repository

$ git remote -v

Sync the fork

Go to your local project and fetch the remote, bringing the branches and their commits from the upstream repository. You can use the -p, --prune option to delete any remote-tracking references that no longer exist in the remote. Commits to master will be stored in a local branch, upstream/master

$ git fetch upstream

Check out the branch you want to merge into (your fork's local master branch)

$ git checkout master

Merge the changes from upstream/master into your local master branch. This brings your fork's master branch in sync with the upstream repository, without losing your local changes. If your local branch didn't have any unique commits, Git will instead perform a "fast-forward".

$ git merge upstream/master

Syncing your fork only updates your local repository. To update your fork on GitHub, push your changes.

$ git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment