Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch someone else's pull request (to fix it)

Tags:

git

github

We are a team of programmers.

We have the main repo for one project.

One of programmers in our team made a pull request to that repo.

I need to fix his pull request. And I'm not a main repo owner.

How do I fetch his code?

When I go to his account - I don't see the fork of that repo (probably it's private).

Is it done like so?:

$ git remote add <name> <source> # for <source> - link to his pull request
$ git fetch <name>
$ git merge <name>/<branch>
like image 462
Serge Vinogradoff Avatar asked Jan 21 '14 10:01

Serge Vinogradoff


People also ask

How do I pull down someone else's branch on GitHub?

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> .


2 Answers

Simply

git fetch origin pull/<pull-request-id>/head:<local-branch-name>
git checkout <local-branch-name>

If you're on a fork not the main repo, you'll need to add the main repo as another remote (here called upstream), then fetch from that remote:

git remote add upstream [email protected]:whoever/whatever.git
git fetch upstream pull/<pull-request-id>/head:<local-branch-name>
...

(note: in this case you obviously can't push commits to the pull request)

like image 121
SColvin Avatar answered Sep 27 '22 23:09

SColvin


  1. Add remote pointing to other programmers repo/branch:

    git remote add ...
    
  2. Create other's branch name:

    git branch other_branch
    
  3. Change a branch to other's:

    git checkout other_branch
    

    NOTE: of course you can join the command to previous one in the single line:

    git checkout -b other_branch
    
  4. Pull other source commits:

    git pull other_source other_branch
    
  5. Fix his code;

  6. Add and commit changes:

    git add
    git commit
    
  7. Then either push the changes into his branch, so they automatically will be added into the pull-request, then accept the request.

    In case the access will be unauthorized you have to merge the changes before fixing the code, then merge the code into the main development branch, and push the changes into repo. However you shell to cancel the pull-request.

like image 35
Малъ Скрылевъ Avatar answered Sep 28 '22 00:09

Малъ Скрылевъ