Reviewing the PRs - The Perfect Way.
Tags: git, beginners, tutorial, github
Published: 2024-01-15 14:25:16

**Introduction:**

Maintaining a flawless master branch is the bedrock of a robust codebase. In the world of collaborative coding, understanding how to meticulously review pull requests on GitHub becomes imperative. Let's understand how to streamline this process and ensure the master branch remains a bastion of pristine code.

**The Project Environment:**

Imagine a project with a master branch where four developers toil away on their individual upstream branches. Each developer meticulously crafts their code, creating a personal branch that acts as a gateway to the master. Now, let's dive into the intricacies of the review process.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/92gkb33cjtkh8mqz5dr0.png)

**The Reviewer's Toolbox:**

As the designated reviewer, your begin the process by switching to the master branch:
`git checkout master`
and pulling the latest changes.
`git pull`
Now to test the changes in a separate environment and to keep your local copy of master branch bug free and to skip the process of stashing or reverting before you merged the changes from pull request, I find making a local copy of your master branch very useful.
Let's create a local copy of your master branch where we will pull the changes from PR and that can be done by the below command:
`git branch -d master_testing`.

As we have already taken a pull at our master branch we can directly merge the developer's code into out testing branch.
`git merge origin/[NAME OF DEV's Upstream Branch]`

At any given point of time if you want to understand what needs to be done you can always check the command line instructions on PR as well:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w4nwsw7py8keleqkba2w.png)

This is where you can find all the steps you need to do in order to clone the changes of a PR:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/no9nwcufhci3nwdrkftf.png)

Now, let's say at any point of time you want to request some changes that needs to be done you can always comments about what needs to be done for the developer using the Comment on this file feature:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fcb3djaqyjdhblortjla.png)
Now let's assume I want the developer to add proper error handling in a file, that can done by raising a comment which can be seen by the developer on the PR page


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7r51v6d0k7574xcd67fi.png)
Once you have added your comment you can submit the review with general feedback

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tm9okirhcm6zcuzn9dxx.png)

which can we be seen on the conversation page like below

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ylb259y7z3v8ssqcoh24.png)

Once the developer has added the error handling as per your comment he can just push to the upstream branch and you can review the changes and resolve the conversation and you are all set.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x8sxqapxis4slnm473v9.png)

Now you can successfully merge the pull request with your master branch.

And there you have it a PR reviewed and merged with your master branch without hampering your local master branch.

The below image would be useful to visualize the process that we followed.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7lq5mpe0m7g3vi8h793p.png)

The interaction culminates in the GitHub UI, where comments become the canvas for collaboration. Any changes, suggestions, or concerns find their place in this digital dialogue. It's a seamless way to iterate, ensuring the final code aligns with the project's standards.

**Conclusion:**

Mastering the art of pull request reviews on GitHub is not just a technicality; it's a testament to collaborative coding excellence. By creating a robust workflow — from pulling the latest changes to leveraging git stash for refinement — the reviewer becomes the guardian of a pristine master branch. With these tools in hand, the development journey becomes not just efficient but a testament to the power of collaborative coding.

Thank you for reading! If you have any questions or feedback about this article, please don't hesitate to leave a comment. I'm always looking to improve and would love to hear from you.

Also, if you enjoyed this content and would like to stay updated on future posts, feel free to connect with me on [LinkedIn](https://www.linkedin.com/in/aditya-mathur-52322b16a/) or [X](https://twitter.com/adii_mathur) or check out my [Github ](https://github.com/adii9)profile. I'll be sharing more tips and tricks on Django and other technologies, so don't miss out!

If you find my content valuable and would like to support me, you can also [buy me a coffee](https://www.buymeacoffee.com/aditya360l). Your support helps me continue creating helpful and insightful content. Thank you!