How to synchronize fork in Git?

How to synchronize your fork to keep it up-to-date with the upstream repository?
I forked a project and contributed some features in my separated repository. At the same time, the project also got some changes, so now my fork is not updated with the main project. How can I update my fork with the main project?

Solution:

By design, forking a project creates a separated repository which is not updated when the original repository changes. However, we can do it manually and it's pretty easy.
What we have is 3 repository:
  1. Upstream: the upstream project's repository on Github
  2. Origin: my fork's repository on Github
  3. Local: my local repository on my laptop.
    (cloned by using git clone git@github.company.com:myfork/project.git)
Steps:
  1. Add the upstream project as a remote:
    git remote add upstream git@github.company.com:main/project.git
  2. Pull changes from upstream remote master branch into my local repository master branch:
    git pull upstream master
  3. Now my local repository is synchronized with upstream, then push my local repository to my fork:
    git push origin master

No comments:

Post a Comment

Genuine websites to earn money.

If you are interested in PTC sites then this article is for you. I have personally tried many of the sites and found that the best thing ...