Skip to content

How to handle depending Pull Requests on GitHub

Matthias Diener edited this page Jul 7, 2020 · 17 revisions

Linear dependency

Suppose we want to implement two features, feature1 and feature2, with feature2 depending on feature1.

Create branches

$ git checkout master
$ git checkout -b feature1 # Create feature1 branch off the master branch
# [...]
# implement and commit feature1

$ git checkout feature1
$ git checkout -b feature2 # Create feature2 branch off the feature1 branch
# [...]
# implement and commit feature2

Working with Pull Requests (PRs)

1. Push changes

$ git checkout feature1
$ git push
$ git checkout feature2
$ git push

2. Open Pull Requests

Feature1

The feature1 PR should have master as the base branch.

Feature2

The feature2 PR should have feature1 as the base branch.

3. Merge Pull Requests

In general, PRs should be merged separately, i.e., do not combine feature1 and feature2 into a single PR:

  1. Merge the feature1 PR as usual.

  2. Change the base branch of the feature2 PR to master by clicking on the 'Edit' button on the top left and changing the base branch.

    ℹ️ Note that GitHub will change the base branch automatically if you delete the feature1 branch after merging it.

  3. Now feature2 can be merged.

If there is a chain of branches depending on each other, these can be handled in a similar way.

Non-linear dependency

Suppose we have the same example as above (two features, feature1 and feature2, with feature2 depending on feature1), but also a dependence of feature2 on featureA (which does not depend on anything). In this case, the handling is a bit more complex.

# Create feature1, feature2 branches as above
# [...]
$ git checkout feature2
$ git merge featureA
# implement and commit feature2

# Create PR:
$ git push

As featureA is now contained in two separate PRs (as a standalone PR and as part of the feature2 PR), care must be taken to not merge featureA as part of feature2. Therefore, annotate the PR for feature2 as follows, assuming that PR #1234 is the standalone PR for featureA:

Depends on PR #1234. Do not merge before #1234 has been merged.

After feature1 and featureA have been merged, change the base branch of the feature2 PR as before, and merge it.

Dependencies across repositories

⚠️ TODO