Skip to content

Instantly share code, notes, and snippets.

@r1990v
Forked from santisbon/Sync-a-Fork.md
Created August 11, 2021 06:55
Show Gist options
  • Select an option

  • Save r1990v/97e4b83da810dd19f76eea78eb038589 to your computer and use it in GitHub Desktop.

Select an option

Save r1990v/97e4b83da810dd19f76eea78eb038589 to your computer and use it in GitHub Desktop.

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