Read Anthropic’s case study about Graphite Reviewer

How to track and resolve pull request dependencies in GitHub

Sara Verdi
Sara Verdi
Graphite software engineer
Try Graphite

Managing pull request dependencies effectively is important in software development, especially in complex workflows with interdependent changes. GitHub provides mechanisms to track and resolve these dependencies, and tools like the Graphite PR inbox enhance this experience. This guide explores how to manage pull request (PR) dependencies in GitHub, as well as offers some practical examples and tips.

Pull request dependencies occur when one PR relies on changes in another to function correctly. These dependencies are common in large projects with modularized codebases or stacked PR workflows. Resolving them effectively minimizes merge conflicts and ensures that changes are reviewed in the proper sequence.

You can explicitly link pull requests to indicate dependencies. Use GitHub's issue or PR linking feature by referencing the dependent PR in the description or comments using #PR_NUMBER. For example:

Terminal
This pull request depends on #42.

This establishes a clear relationship between the two PRs. When the referenced PR is merged or updated, GitHub automatically updates the link's status.

GitHub allows using the phrse "depends on" in PR descriptions to signal dependencies:

Terminal
Depends on #42

This approach communicates dependencies clearly to reviewers and maintainers, helping them understand the order in which PRs should be merged.

To resolve dependencies:

  • Merge the base PR first: Ensure that the PR your current changes depend on is reviewed and merged. This prevents downstream conflicts.

  • Rebase your branch: After the base PR is merged, rebase your branch onto the updated target branch to incorporate those changes. For example:

    Terminal
    git fetch origin
    git rebase origin/main

    This ensures your changes will integrate smoothly.

Stacked pull requests streamline dependency management by logically organizing dependent changes. Tools like Graphite make this workflow seamless. For example, with Graphite, you can create a stack of PRs where each builds on the previous:

Terminal
# navigate to the trunk branch of your repository
gt trunk
# * build part 1 of your feature *
# the following two commands create a new branch off of main with your changes and add a commit
# add all unstaged changes (same syntax as git add)
gt add -A
# create a commit on a new branch with its name inferred from your commit message
gt create
# OR specify your commit message via an option, just like git
gt create -m "part 1"
# OR you can also specify a branch name yourself
gt create making_part_1
# This works too!
gt create -m "part 1" making_part_1
# If you don't run `add`, you'll be prompted to add your changes interactively.
# You can also run `add` as part of the create command with the `-a` flag
gt create -am "part 1"
# You can make the previous command even shorter by using an alias (most common gt commands have an alias, and you can even configure your own!)
gt c -am "part 1"

Each PR is independently reviewable, but the stack ensures the correct order for merging.

The Graphite PR inbox offers a structured way to handle dependencies by organizing pull requests into actionable sections, such as:

  1. Needs your review: Highlights PRs waiting for your input, helping you prioritize dependent PRs.
  2. Merging and recently merged: Allows tracking of PRs that may affect downstream changes.
  3. Custom sections: Create custom filters to group dependent PRs using Graphite's filtering capabilities.

For example, you could set up a section to track all PRs referencing depends on in their descriptions. Sharing these configurations with your team ensures consistency across workflows.

  1. Document dependencies clearly: Use PR descriptions or comments to specify dependencies using keywords like "depends on."
  2. Regularly update branches: Rebase dependent PRs frequently to avoid merge conflicts.
  3. Use automation tools: Automate dependency tracking and notifications using tools like GitHub Actions or Graphite.
  4. Review dependencies before merging: Always ensure base PRs are merged and stable before merging dependent PRs.

By leveraging GitHub's linking features, adopting tools like the Graphite PR inbox, and following these best practices, you can effectively track and resolve pull request dependencies for a smoother workflow.

Built for the world's fastest engineering teams, now available for everyone