Git pull from someone else's fork

M.A.B picture M.A.B · Feb 10, 2017 · Viewed 19k times · Source

We are two students working on our online repository (different repo) that is forked from a common upstream repo.

Let's say other student made Changes, Commits and Pushed to his repo on a specific branch.

  1. How do I pull these changes into my own local repository?

  2. Do I need to commit and push those changes to my staged area?

Thank you!

Answer

Sajib Khan picture Sajib Khan · Feb 10, 2017

Simply add a new remote (say, other) in your own repo. Then Pull other/<branch> changes into your local branch (say, add-other-changes). Push to your own forked repo (origin/add-other-changes). Now, when you done with add-other-changes branch, create a Pull request & merge with origin/master.

  • Pull other repo's changes into your own repo:

    # go into your own repo
    $ git remote add other <other-student-repo-url>  # add a new remote with other's repo URL
    
    $ git fetch other        # sync/update local with other's repo
    
    $ git checkout -b add-other-changes       # create a new branch named 'add-other-changes'                    
    $ git pull other <specific-branch-name>   # pull other/<branch> changes           
    
    $ git push origin HEAD    # push changes to your own(origin) forked repo `add-other-changes` branch