Git pull from someone else's fork
Asked Answered
K

4

46

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!

Know answered 10/2, 2017 at 10:24 Comment(0)
A
79

Add a new remote (say, other) in your own repo. Pull other/<branch> changes into your local branch (say, add-other-changes). Push to your own forked repo (origin/add-other-changes). Now, when're you done with add-other-changes branch, create a Pull request & merge it 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
    
Arnitaarno answered 10/2, 2017 at 10:29 Comment(3)
Perfect ! Thank you :)Know
now that is done, how to track the other student changes ?Know
git fetch other will update your local with other student's repo changes. If you need any specific branch changes then, just pull it git pull other <specific-branch>.Arnitaarno
B
2

For GitHub users:

If you want to pull changes from a Pull Request where the source branch is in a fork, you can use GitHub CLI without adding a remote:

gh pr checkout {<number> | <url> | <branch>}
Bathometer answered 25/4, 2022 at 18:28 Comment(0)
G
1

If you both want to work on the same project, then you shouldn't have forked the the repository twice. You or you friend (not both) should fork the repository, then both of you should clone the forked one in local (permissions need to be granted by the one who forked repository).

Once this is done, when members of the project want to know if there are new changes on the remote, they can do git remote update or more commonly git fetch origin.

If you're working on the same branch and you want to update your local branch with the remote one git pull origin <branh_name>

If one have made changes that should get shared:

git add file_path_1 file_path_2 directory_path1 ...
git commit -m "<your brief message>"
git push origin <branch_name>
Groyne answered 10/2, 2017 at 10:42 Comment(1)
Only applies if the students always have the same group members but not if e.g. first task everyone works alone and submits their own work, second task in pairs, maybe third one in groups of 4.Novelize
M
0

commit and push your working branch. Then do a merge from the main branch to your branch. Ensure all build and resolve any conflicts. commit and push your branch. Now merge your branch into the main branch and it should work.

Meijer answered 10/2, 2017 at 10:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.