Pull Requests and Code Review: The GitHub Workflow for Teams

Collaboration is the backbone of software development, and GitHub has become the go-to platform for teams to work together efficiently. One of the most critical aspects of collaboration is maintaining clean, high-quality code. This is where pull requests (PRs) and code reviews come in. Whether you’re contributing to an open-source project or working in a team on a private repository, understanding how to create pull requests and conduct code reviews is essential.

What is a Pull Request?

A pull request (PR) is a request to merge changes from one branch into another. It allows team members to review, discuss, and approve changes before they are merged into the main codebase. Think of it as submitting an assignment for grading—your peers and team leads will check your work before it gets accepted.

From https://www.atlassian.com/blog/bitbucket/5-pull-request-must-haves

Step-by-Step Guide: Creating a Pull Request on GitHub

Step 1: Fork and Clone the Repository (If Contributing to Open Source)

If you are contributing to an open-source project, first fork the repository and then clone it to your local machine.

# Fork the repository on GitHub
# Clone it to your local machine
git clone https://github.com/your-username/repository-name.git
cd repository-name

Step 2: Create a New Branch

Always create a new branch for your changes rather than working directly on the main or master branch.

git checkout -b feature-branch-name

Step 3: Make Changes and Commit

Modify the code as needed. Once done, stage and commit your changes.

git add .
git commit -m "Added new feature X"

Step 4: Push the Changes

Push the changes to your repository on GitHub.

git push origin feature-branch-name

Step 5: Open a Pull Request

  1. Go to your GitHub repository.
  2. Navigate to the Pull Requests tab.
  3. Click New Pull Request.
  4. Select your feature branch as the source and main branch as the destination.
  5. Add a title and description explaining your changes.
  6. Click Create Pull Request.

Tip: Write clear, descriptive PR titles and descriptions so that reviewers understand the purpose of your changes.

The Importance of Code Review

A pull request is not complete until it has been reviewed and approved by your team members. Code review ensures that:

  • Bugs and potential issues are caught early.
  • Code follows best practices and team guidelines.
  • The implementation aligns with project goals.
  • Developers learn from each other, improving overall team quality.

How to Review a Pull Request on GitHub

  1. Navigate to the Pull Requests section of the repository.
  2. Click on a pending PR.
  3. Go through the changed files.
  4. Add comments where needed.
  5. If everything looks good, click Approve & Merge.

Tip: Use inline comments to suggest improvements and provide constructive feedback.

Best Practices for Code Review

  • Be polite and constructive – Frame suggestions positively.
  • Look for logical errors – Ensure the code functions correctly.
  • Check for style and formatting – Follow team conventions.
  • Suggest better approaches – Help improve efficiency and readability.

Approving and Merging a Pull Request

Once a PR is reviewed and approved:

  • Click Merge Pull Request.
  • Choose Squash and Merge (for cleaner commit history) or Rebase and Merge.
  • Delete the feature branch if it’s no longer needed.

After merging, sync your local repository with:

git checkout main
git pull origin main
git branch -d feature-branch-name

Video Guide:

Conclusion

Mastering pull requests and code reviews is an essential skill for every developer. Whether you’re contributing to open-source projects or working within a team, these practices ensure high-quality, maintainable code.

By following the steps outlined above, you’ll be well on your way to effective collaboration and seamless development workflows.

Happy Coding!

Further Reading: