Checkout a pull request (PR) on a repository that you have forked

When you start working in Open-Source, one of the incredible ways to help out is by testing and reviewing PRs.

Since I've been maintaining the Codú platforms codebase, I often have to checkout PRs locally, and I know it confused me when I started, so hopefully this verbose example helps.

This guide assumes you have forked the codebase and locally cloned the fork.

Make sure you set your upstream.

If you have already set up your upstream, skip to the next section.

To get changes from the parent repository that you forked from you need to make sure you have it set as upstream.

The following is from a GitHub guide (where you can find here).

List the current configured remote repository for your fork.

$ git remote -v
> origin (fetch)
> origin (push)
git remote add upstream

Verify the new upstream repository you've specified for your fork. You should see that your upstream is set correctly by rerunning the git remote -v command.

$ git remote -v
> origin (fetch)
> origin (push)
> upstream (fetch)
> upstream (push)

And an example of the output from my config from this repo.

$ git remote -v
> origin (fetch)
> origin (push)
> upstream (fetch)
> upstream (push)

Checking out a PR on the parent repository

The first thing you need to do is fetch the changes in the PR.

Run the following command to fetch the changes from the upstream repository:

git fetch upstream pull/ID/head:BRANCHNAME

Replace ID with the number of the pull request and BRANCHNAME with the name of the PR branch you are trying to checkout.

You should now have a local branch with the changes from the pull request that you can review, test, and alter locally if you wish.


As a real-world example from a PR currently open on Codú as I'm writing this. 👇

Screenshot of an open PR including a PR number and branchname

$ git fetch upstream pull/163/head:dancallaghan/user_prompt_unsaved_changes_issue11

Then checkout the branch:

$ git checkout dancallaghan/user_prompt_unsaved_changes_issue117                   
> Switched to branch 'dancallaghan/user_prompt_unsaved_changes_issue117'


Happy coding. 👨🏻‍💻

Open SourceCodingGithubTerminal
Avatar for Niall Maher

Written by Niall Maher

Founder of Codú - The web developer community! I've worked in nearly every corner of technology businesses; Lead Developer, Software Architect, Product Manager, CTO and now happily a Founder.


Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.