10

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>
1
  • git pull ${his_fork_url_here}
    – cnd
    Jan 21, 2014 at 10:12

2 Answers 2

7

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 git@github.com: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)

1
  • 1
    This is way easier and better than "top" answer Jan 20, 2021 at 18:49
4
  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.

1
  • huh on my git you specify the branch as an argument after git add remote
    – marinara
    Oct 9, 2020 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.