I forked someone's repository on GitHub and would like to update my version with commits and updates made in the original repository. These were made after I forked my copy.
How can I pull in the changes that were made in the origin and incorporate them into my repository?
On GitHub, navigate to the main page of the forked repository that you want to sync with the upstream repository. Select the Sync fork dropdown. Review the details about the commits from the upstream repository, then click Update branch.
Go to your fork, click on Fetch upstream , and then click on Fetch and merge to directly sync your fork with its parent repo. You may also click on the Compare button to compare the changes before merging.
Sync from the UI Clicking on that you have the possibility to compare the changes made in the source repo with the ones made in your forked repo, and also to automatically fetch and merge them into your repo.
You have to add the original repository (the one you forked) as a remote.
From the GitHub documentation on forking a repository:
Once the clone is complete your repo will have a remote named “
origin
” that points to your fork on GitHub.
Don’t let the name confuse you, this does not point to the original repo you forked from. To help you keep track of that repo we will add another remote named “upstream”:$ cd PROJECT_NAME $ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git $ git fetch upstream # then: (like "git pull" which is fetch + merge) $ git merge upstream/master master # or, better, replay your local work on top of the fetched branch # like a "git pull --rebase" $ git rebase upstream/master
There's also a command-line tool (hub
) which can facilitate the operations above.
Here's a visual of how it works:
See also "Are Git forks actually Git clones?".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With