Introduction
In this post, we'll learn how to fetch a pull request locally and test it out before merging it into our project repository. We can also make changes to it if required and push those changes as well.
Testing the PR locally
Suppose, we have an open source project on GitHub and contributors are contributing to it in the form of issue fixes or adding new features by opening a pull request to our repository. Now, we want to test these pull requests before merging it into our repository. We can do so by following the below steps:
- Navigate to the pull requests tab on your repository in GitHub and copy the pull request id that we want to test. The pull request id is present right after its title.
- Now, open Git Bash and navigate to your project directory and run the following command
git fetch origin pull/ID/head:BRANCHNAME
Replace the ID
with the actual pull request id and BRANCHNAME
with the branch name to which the pull request changes will be copied.
Suppose the pull request id is 10
and the branch name we wish to create is demo-feature
. Therefore, the command that we'll run
git fetch origin pull/10/head:demo-feature
- Now, switch to the new branch created with the pull request changes using the following command
git checkout demo-feature
Now, we can run our project on this branch and test out the pull request changes. We can then merge the pull request once we are done analysing the changes and confirming that everything is working the way it should.
We can also add changes to the pull request and after committing those changes, we can push those changes to GitHub using
git push origin demo-feature
Conclusion
In this post, we learned how to test a pull request locally before merging it into our project and also learned that changes can be made to the pull request and pushed to GitHub.
Thanks for taking the time to read this post. I hope this post helped you in learning something and if you enjoyed it, please share.
It would be great to connect with you on Twitter. Please do share your valuable feedback and suggestions👋
Comments (0)