DEV Community

Cover image for Small Tips to merge GitHub pull-request into your local repository
Yasuhiro Matsumoto
Yasuhiro Matsumoto

Posted on • Updated on

Small Tips to merge GitHub pull-request into your local repository

PRO tip to merge GitHub pull-request into local repository easily.

How are you doing checkout GitHub pull-request on local repository?

$ git fetch origin pull/ID/head:BRANCHNAME
Enter fullscreen mode Exit fullscreen mode

ID is pull-request number, BRANCHNAME is name of local branch you will create

Like this? Would you remember this format in tomorrow? thinking Maybe I don't.

Thankfully GitHub serve some extra contents with appending file extension into URLs. See Diff and patch media types. For example, put .diff to the end of pull-request URL:

"https://github.com/vim/vim/pull/2070" + ".diff"
Enter fullscreen mode Exit fullscreen mode

https://github.com/vim/vim/pull/2070.diff

This request will be redirected to the page of unified diff. If put .patch to the URL of pull-request.

"https://github.com/vim/vim/pull/2070" + ".patch"
Enter fullscreen mode Exit fullscreen mode

https://github.com/vim/vim/pull/2070.patch

This will be redirected to the patch file. So you can try to apply the diff like below.

$ curl -sL https://github.com/vim/vim/pull/2070.diff | patch -p1
Enter fullscreen mode Exit fullscreen mode

Also if you want to merge pull-request into your local repository,

$ git checkout -b pr-2070
$ curl -sL https://github.com/vim/vim/pull/2070.patch | git am
Enter fullscreen mode Exit fullscreen mode

Do tests and push into master branch.

$ git checkout master
$ git merge pr-2070
$ git push origin master
Enter fullscreen mode Exit fullscreen mode

Can you see that? It's not difficult at all.

Top comments (0)