Understanding pull request merge processes and best practices

Sara Verdi
Sara Verdi
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


In GitHub, pull requests are the primary method through which code is reviewed, discussed, and added to the main project branch. This guide takes a look at the merge processes of pull requests, best practices, and how to utilize Graphite's merge when ready feature.

When a developer wants to merge changes from one branch into another—typically from a feature branch into the main branch—they open a pull request. This action starts the review process, where team members can discuss, review, and eventually merge the changes into the main branch.

The decision on who merges the pull request often depends on the team's workflow and the complexity of the project. Best practices suggest that the person responsible for the merge should be either:

  • The pull request author, after receiving the necessary approvals.
  • A designated reviewer or a team lead, who ensures the changes meet all project standards before merging.
  1. Require code reviews before merging:

    • Ensure that every pull request is reviewed by at least one other team member before it is merged. This practice helps catch errors, improves code quality, and shares knowledge across the team.
  2. Keep pull requests small and focused:

    • Limit pull requests to a manageable size and scope to simplify reviews and reduce integration issues. Small, focused pull requests are easier to understand, quicker to review, and less likely to cause conflicts when merging. Research suggests you should keep the length of a PR between 50 - 200 lines when possible.
  3. Run automated checks:

    • Use continuous integration (CI) tools to run automated tests and checks on every pull request. This step ensures that the new code meets quality standards and does not break existing functionality.
  4. Update and rebase frequently:

    • Regularly update and rebase the pull request branch to keep it current with the base branch (usually main). This practice reduces merge conflicts and allows for smoother integration of changes.
  5. Document the rationale behind changes:

    • Encourage detailed descriptions and comments in pull requests to explain why changes were made. This documentation is invaluable for reviewers and for future reference.
  6. Define and enforce merging criteria:

    • Set clear criteria that must be met before a pull request can be merged, such as passing all CI checks, obtaining necessary approvals, and ensuring that all discussions are resolved.
  7. Utilize draft pull requests for work-in-progress:

    • Leverage draft pull requests for ongoing work to gather early feedback and suggestions. This approach helps improve the quality of the final changes.
  8. Automate where possible with tools like Graphite’s Merge when ready:

    • Implement tools like Graphite’s Merge when ready feature to automate the merging process once all predefined conditions are met. This automation saves time and reduces manual errors.
  9. Educate and train contributors:

    • Provide guidance and training on your project’s pull request processes to ensure everyone understands how to create, review, and merge pull requests effectively.
  10. Review the impact post-merge:

    • After merging, monitor the impact of changes on the project's performance and stability. Quick feedback loops can help identify issues early, promoting a more agile development environment.

By implementing these best practices and utilizing features like Graphite's merge when ready toggle, teams can optimize their pull request process, to enhance both productivity and code quality.

Git inspired
Graphite's CLI and VS Code extension make working with Git effortless.
Learn more

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2