-
Notifications
You must be signed in to change notification settings - Fork 23
How to handle depending Pull Requests on GitHub
Suppose we want to implement two features, feature1 and feature2, with feature2 depending on feature1.
$ 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$ git checkout feature1
$ git push
$ git checkout feature2
$ git pushThe feature1 PR should have master as the base branch.
The feature2 PR should have feature1 as the base branch.
In general, PRs should be merged separately, i.e., do not combine feature1 and feature2 into a single PR:
-
Merge the
feature1PR as usual. -
Change the base branch of the
feature2PR tomasterby 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
feature1branch after merging it. -
Now
feature2can be merged.
If there is a chain of branches depending on each other, these can be handled in a similar way.
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 pushAs 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.