How can I Resync a fork from original
Solution 1
By design, forking a project creates a separate repo that is not updated when the original repo changes. However, git
makes it pretty easy to update manually.
You need the help of a 3rd repository (your local copy suffices). There are 3 repos:
- "Upstream": The upstream project's repository on Github.
- "Origin": Your fork's repository on Github
- "Local": Your local repository on your computer. I will assume you created it by cloning Fork using
git clone [email protected]:your-username/projectname.git
, and that everyone is using branchmaster
.
Assuming currently "Origin" and "Local" are in the same state, and "Upstream" is ahead by 1 or more commits (the merge and any subsequent changes).
First add the upstream project as a Git remote:
git remote add upstream https://github.com/upstream-username/projectname.git
Then pull (meaning fetch and then merge automatically) the changes from the remote's master
branch into your local repository's current (master
) branch:
git pull upstream master
Now your local repository is in sync with upstream
. Finally, push your local repo to your Github fork:
git push origin master
Now everything is in sync.
Solution 2
You need to add a remote (see GitHub help) and pull from that new remote.
git remote add mainProject https://github.com/user/mainProject
git pull mainProject master
Related videos on Youtube
bAN
Updated on September 18, 2022Comments
-
bAN over 1 year
I just forked a project in Github. I made modifications and sent a pull request. The owner merged my fork with the main project and after that he made some modifications. So for now my fork is not updated with the main project. I miss the modifications he made after merging my pull request. How can I update my fork with the Main project? Is there a way to do that in the web interface?
Thanks
-
Admin about 10 yearsI write a simple instruction. check out at here: webapps.stackexchange.com/a/58140/63016
-
Admin about 10 yearsThere's now an official doc which is well done: help.github.com/articles/syncing-a-fork
-
-
bAN over 11 yearsThanks a lot.. it's a shame that this may not be possible to make that in the web interface..
-
thSoft over 11 yearsThis is indeed possible on the web interface: webapps.stackexchange.com/a/31010/10390
-
pepoluan over 9 yearsYeehaw! I had been tearing my hair out trying to find this explicit info. Thanks for sharing!
-
usr-local-ΕΨΗΕΛΩΝ over 9 years... but please take also a look at the answer's comments, proving that Resync via web is not the best option as it pollutes repository
-
roberto tomás about 9 yearswhat do you do when it says "already up to date" after the pull, but it is obviously not? (there are files I changed all in one subdirectory, and I should have no differences in any other file, but I do)