Question

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

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!


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
October 19, 2024
Accepted Answer

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

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.