Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git pull from someone else's fork

Tags:

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!

like image 585
M.A.B Avatar asked Feb 10 '17 10:02

M.A.B


People also ask

How do you pull someone else's fork?

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 .

How do you pull from someone else's branch?

If you want to check out a remote branch someone published, you first have to use git fetch . This command downloads the references from your remote repository to your local machine, including the reference to the remote branch. Now all you need to do is use git checkout <remote branch name> .

How do you fetch from a fork?

Go to your fork, click on Fetch upstream , and then click on Fetch and merge to directly sync your fork with its parent repo. You may also click on the Compare button to compare the changes before merging.


2 Answers

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 
like image 134
Sajib Khan Avatar answered Sep 17 '22 20:09

Sajib Khan


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> 
like image 37
smarber Avatar answered Sep 19 '22 20:09

smarber