Working while waiting for pending PR
GitPull RequestGit Problem Overview
I'm working on a project and I submitted my first pull request and while I'm waiting I want to continue on working on my project building up from what I worked on the merge that's still pending on. Right now I have :
*master
user_story_1
user_story_1
has an open pull request.
Now I'm trying to create a new branch user_story_2
where I can continue the work I left of at user_story_1
. How can I do this in Git without getting into any conflict or affecting my pending merge?
Git Solutions
Solution 1 - Git
I'm assuming you want to start the new user_story_2
branch on top of the work you've done in user_story_1
. Here's the workflow I use in this sort of scenario:
-
Open Pull Request for
user_story_1
:* (user_story_1) * / * (master) * *
-
Create new branch
user_story_2
based onuser_story_1
:$ git checkout -b user_story_2 user_story_1
* (user_story_1, user_story_2) * / * (master) * *
-
Work on the new branch:
* (user_story_2) * * (user_story_1) * / * (master) * *
-
Pull Request gets merged:
* (user_story_2) * * | (master) |\| | * (user_story_1) | * |/ * * *
-
Delete old branch:
* (user_story_2) * * | (master) |\| | * | * |/ * * *
-
Rebase new branch onto
master
:* (user_story_2) * / * (master) |\ | * | * |/ * * *
Solution 2 - Git
My preferred workflow for this:
- On branch master,
git checkout -b user_story_1
. - Make changes to
user_story_1
. - Open PR for
user_story_1
. - On branch
user_story_1
,git checkout -b user_story_2
. - Make changes to
user_story_2
. - Once
user_story_1
gets merged into master, switch touser_story_2
and dogit rebase -i master
. - This should show you a list of commits on
user_story_2
that you want to include in the rebase. Delete the top few commits that came fromuser_story_1
. - The rebase should complete cleanly unless master was updated with other changes. Now you have
user_story_2
rebased on master and only having its commits.
Solution 3 - Git
Create a new branch from master for each of your stories/features.
Before merging each branch back, either merge master into that branch or rebase your branch onto master. The latter has my preference, but in the end the outcome is the same.
You are going to get conflicts, there is no way around that. However, you want to solve conflicts in your branch; not in master. This way, you can test your branch after resolving the conflicts before merging it into master.