56

I cloned this repo on my computer: https://github.com/derobins/wmd.git

There are several bugs with it though, and it looks like another user has fixed them and issued "Pull requests" (I assume these are requests for their changes to be committed?)

Is it possible to merge those changes into my local version?

EDIT: just to be clear, this is not my repository. I am using the WMD editor from derobins, but it has several bugs which those pull requests purport to fix. I have cloned the repo on Ubuntu (not in github) and was hoping to merge those changes in if possible.

DisgruntledGoat
  • 70,219
  • 68
  • 205
  • 290

2 Answers2

58

(GitHub has very thorough documentation on how to deal with pull requests.)

Essentially, you'll want to add a remote for the repository of the person who made the pull requests, e.g.:

git remote add helpful git://github.com/helpful-person/whatever.git

... then fetch their changes into remote-tracking branches:

git fetch helpful

... so that now you have all the commits from that person's GitHub repository in your clone of the upstream repository. If you look at the additional commits within that pull request you could:

  1. merge the latest one, e.g. git merge 75708aeab5
  2. cherry pick each of those changes, e.g. git cherry-pick 2142db89, git cherry-pick 75708aeab5
  3. create a local branch to work on them further, e.g. git checkout -b fix-for-issue3 75708aeab5
  4. etc. etc.

An alternative is to just clone the repository of the contributor who made the pull requests instead, if that's the same but for those fixes.

David Birks
  • 163
  • 2
  • 5
Mark Longair
  • 446,582
  • 72
  • 411
  • 327
  • Btw i would first checkout helpful/essential-fix and rebase it on my master, after this checking out master and then merging helpful/essential-fix – kalkin Apr 05 '11 at 14:25
  • There are endless variations on what the OP could once he's fetched the commits from the pull request - I was describing a simple one with an explicit proviso. – Mark Longair Apr 05 '11 at 14:29
  • 1
    Would be nice if there were a single command, e.g. git merge https://github.com/repo/project/pull/119 ... if you want something lightweight you can BTW `curl https://github.com/repo/project/pull/119.patch` then apply the patch – Partly Cloudy Jun 05 '12 at 11:05
  • 3
    @PartlyCloudy: well, you could just do: `git pull git://github.com/helpful-person/whatever.git [SHA1-of-commit-at-tip-of-pull-request]` – Mark Longair Jun 06 '12 at 10:32
34

The accepted answer suggests to clone or add remote for the repository of the person who made the pull request. Another cleaner and simpler way is to use this command

git pull https://github.com/otheruser/repo.git branchname

For example, at the time of writing, ghi has three open pull requests that haven't been merged yet. This is what I did to merge them into my local repo.

# I want to make sure my master is in sync with the upstream master
git checkout -b merge-patches master
# first pull request
git pull --no-ff https://github.com/TiddoLangerak/ghi.git master
# second pull request
git pull --no-ff https://github.com/wayfare/ghi.git master

Note that both pull requests were sent from master that is why I pulled from their master branch.

This way, other repositories do not get added to your remotes, neither you have to cherry pick or clone them locally.

DisgruntledGoat
  • 70,219
  • 68
  • 205
  • 290
Andrew-Dufresne
  • 5,464
  • 7
  • 46
  • 68
  • I liked this answer best, although this didn't work form me. I kept getting `fatal: Couldn't find remote ref action-schema Unexpected end of command stream` – Daniël W. Crompton Nov 02 '13 at 01:36
  • 2
    @DaniëlW.Crompton Most likely reason is that git repository URL is incorrect. – Andrew-Dufresne Nov 02 '13 at 03:44
  • @MonsterMMORPG In this case, submitter has deleted his repository, as indicated by `unknown repository` in "filipkristo wants to merge 1 commit into DetectiveSquirrel:master from unknown repository". You will have to download patch and apply it manually. You can download patch from this link https://patch-diff.githubusercontent.com/raw/DetectiveSquirrel/Pokemon-Go-Rocket-API/pull/48.patch and to apply the patch see `git apply`. Here is a nice tutorial on git patches https://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git/ – Andrew-Dufresne Jul 25 '16 at 15:47