Report this

What is the reason for this report?

How to check out a PR from an upstream repo locally?

Posted on August 29, 2024

I’ve forked a repository and need to review a PR from the original upstream repo.

Normally, I’d just fetch branches manually, but I’ve heard there might be a simpler way to handle this using a tool or command. I’m particularly interested in checking out the upstream PR directly into my local environment.

Is there an efficient way to do this? If so, what’s the best approach?

I’d appreciate any guidance or instructions on how to make this process easier!



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey there!

There’s actually a fairly easy way to check out a pull request from the upstream repo using the GitHub CLI (gh).

If you don’t already have it installed, you can grab it from here.

Once you’ve got gh set up, here’s what you need to do:

  1. First, make sure you’ve added the upstream repo as a remote (if you haven’t already):

    git remote add upstream https://github.com/ORIGINAL_OWNER/REPO_NAME.git
    
  2. Next, use this command to check out the PR locally:

    gh pr checkout PR_NUMBER --repo upstream-repo
    

    Replace PR_NUMBER with the actual pull request number and upstream-repo with the correct repo name (e.g., original/repo).

  3. After that, you’ll be on the PR branch, and you can review or work on the code just like any other branch.

If you don’t want to install gh, you could still do this the old-school way by fetching the PR branch manually, but trust me, the CLI makes it way easier!

Hope this helps! Let me know if you run into any issues! 👍

- Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.