What is the best way to approach this?
If it were me, I'd just leave it and move on. As soon as the first PR is completed and feature/foo
gets merged into develop
, your second PR should be able to be updated such that the changes from the previous PR will disappear1. However, if you have a rebase or squash merge strategy on your PRs, and the first branch is re-written, even though the changes will fall out of the PR, the commits will not. If you don't want to see those commits in the 2nd PR, after the first is completed you could do a "fancy" rebase of feature/foo2
to update it:
git fetch
git rebase feature/foo feature/foo2 --onto origin/develop
git push --force-with-lease
Note in the above command you want to use your local copy of feature/foo
and the remote copy of the develop
, which is why it's specified as origin/develop
.
What can I do differently?
Some options that might apply to you:
- You could skip working on a feature that depends on something that isn't merged into
develop
yet and pick something else.
- You could take action to get the first PR completed faster. (Perhaps try to meet with the reviewer(s) and get it reviewed and completed immediately.)
Side Note: when you must start working on a feature that depends on another branch not yet completed into develop
, assuming that other branch is up to date (especially if you use a rebase workflow), then you could just branch off of the previous branch instead of the multiple command approach you presented. Instead of:
git switch -c feature/foo2 origin/develop
git merge feature/foo
you could simply do:
git switch -c feature/foo2 feature/foo
1This is implementation dependent, but many PR tools automatically update the PR when the source branch changes, and also offer a mechanism for updating the PR when the target branch changes, though you might have to pick an option such as "Restart Merge" or similar.