Search code examples
gitgit-mergegit-pullgit-forkgit-fetch

Forked a repo. The master added commits. How do I fetch those additions?


So, I recently started contributing to Open Source projects on Github. Until now, I was just putting my own personal projects up there.

Now, I forked a repo of an org that I found interesting. But, I see that that org has added commits to the master. I believe that my work can result in a merge conflict.

What I need help with:

  • I need to know how to pull the code that has been committed in the master branch of the org to my forked master branch.

Solution

  • You should be able to sync your fork to the original master by doing the following:

    1. Specify the original repository as a new remote upstream repo

      git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
      

      You can then run git remote -v to confirm the upstream repository has been added correctly

    2. Fetch from upstream branches (master commits will be in upstream/master)

      git fetch upstream
      
    3. Merge the changes from the upstream master into your local master (bringing your fork in sync)

      git merge upstream/master
      

    For a full step by step guide please see https://help.github.com/articles/syncing-a-fork/