Serge Vinogradoff
Serge Vinogradoff

Reputation: 2272

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

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>

Upvotes: 10

Views: 13970

Answers (2)

Samuel Colvin
Samuel Colvin

Reputation: 13279

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)

Upvotes: 8

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

Reputation: 16507

  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.

Upvotes: 4

Related Questions