DEV Community

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

Posted on • Edited on

13

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.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay