DEV Community

Bolaji Ayodeji
Bolaji Ayodeji

Posted on • Updated on • Originally published at

How to test a Pull Request locally before Merging.

In this article, I would show you how to check, test and make changes to a pull request before merging.

So your repository got a new Pull Request?, You don't want to merge it before testing it out yourself locally on your machine. How do you go about it?

The pull request is available on this git ref pull/{ID}/head which you can fetch using this, where ID is the pull request id.


  • Make sure you have a cloned version of the repository on your machine,
    Check here to learn how to clone repositories from GitHub.

  • Have your cloned Repository integrated into your IDE
    preferably Visual Studio Code [In this
    tutorial, I used VsCode]

  • Be conversant with git commands

  • Go to your repository folder

  • Initialize git (you can do that by right-clicking in the root folder)

  • Ensure your work tree is clean (you can do that by running git status)

  • Run the following commands to FETCH the pull request from GitHub where ID is the pull request's ID

git fetch origin pull/ID/head && git checkout FETCH_HEAD

Or, if you only want to cherry pick it, instead of checking it out, you can use

git fetch origin pull/ID/head && git cherry-pick FETCH_HEAD
  • Open your IDE (VsCode) Your folder structure should change now pending on the contents of the PR.

What you have now is the contents of the pull requests and not your master
branch, run your checks and tests to determine if the pull request is worth merging.

At this point, you can do anything you want with this branch. You can run some local tests, or merge other branches into it, including master. Make modifications as you see fit!

Once satisfied git checkout master to return to the master branch.

You can also make changes to the pull request and push back to GitHub as a new commit or pull request.

After making your changes:

git add --all
git commit -m "Modified PR"
git push origin BRANCHNAME (e.g master or test)

That's it, you have tested the pull request and made changes!

If this article helped you, share!!!

Top comments (3)

olaoluwa98 profile image
Emmanuel Awotunde

Nice one!

When you cherry pick doesn't apply the commits to your current branch?

bolajiayodeji profile image
Bolaji Ayodeji

Hi Emmanuel,

Cherrypick allows you to apply the changes introduced by some existing commits. It's more of picking a commit from a branch and applying it to another. Read this, to see it's use cases here. Hope this helps!

olaoluwa98 profile image
Emmanuel Awotunde

Oh nice, that would really be a game changer for the way I review PRs.