A user submitted a PR for my repo. How do I check the changes locally before merging them?

A user has forked my repo and submitted a PR to me. I’m trying to figure out how to review it locally before merging the changes. The docs I’ve found suggest using the Open With/Checkout with Git Desktop link from the PR page, but this is failing for me. At first TortoiseGit was trying to open the link instead of GitDesktop, but even after I manually select the Git Desktop binary, when it opens is just shows my master branch and not the PR.

Is there some other way to do this?

You can always add the fork as another remote to your local repository and check out the relevant branch, the name of the branch is listed on the PR page. You could also do a fresh clone somewhere else from the forked repository, but I think working with a second remote is better because you can easily compare your own and remote code (and also don’t need to duplicate the history).

If you’re not familiar with working with multiple remotes, see: Git - Working with Remotes

1 Like

I would use the CLI for this.

Fetch the reference to the pull request based on its ID number, creating a new branch in the process.

$ git fetch origin pull/ID/head:BRANCHNAME

Switch to the new branch that’s based on this pull request:

[main] $ git checkout BRANCHNAME
> Switched to a new branch 'BRANCHNAME'

Source: Steps 5 and 6 here.

I also personally like this approach, it’s clean and it allows you to even create your own PR on the PR branch, in case you need to propose code changes which the original PR submitter is finding hard to get around to.

1 Like