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:
- Upstream: the upstream project's repository on Github
- Origin: my fork's repository on Github
- Local: my local repository on my laptop.
(cloned by usinggit clone git@github.company.com:myfork/project.git
)
Steps:
- Add the upstream project as a remote:
git remote add upstream git@github.company.com:main/project.git
- Pull changes from upstream remote master branch into my local repository master branch:
git pull upstream master
- 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