Say I work on a branch and make commit A. I make a pull request. While the PR is being reviewed I continue to work on the same branch. Eventually the branch is approved and merged into master. Now that I am ready with commit B, I want to make a new PR. I pull the latest master and rebase my branch on it. The question here is - since master contains commit A because it was approved from my first PR and my branch contains commit A, because I continued my work on it while my first PR was under review, will there be duplicate commits or not? If yes, what is the proper way to make a commit B here - a new branch from the current branch, a new branch off of master and rebasing on the first branch or maybe interactive rebase with cherry picking before the second PR?
From the pull request page you can update your pull request's branch using a traditional merge or by rebasing. A traditional merge results in a merge commit that merges the base branch into the head branch of the pull request. Rebasing applies the changes from your branch onto the latest version of the base branch.
Under your repository name, click Pull requests. In the "Pull Requests" list, click the pull request you'd like to modify. Next to the pull request's title, click Edit. In the base branch drop-down menu, select the base branch you'd like to compare changes against.
Adding line comments to a pull request On the pull request, click Files changed. Hover over the line of code where you'd like to add a comment, and click the blue comment icon. To add a comment on multiple lines, click and drag to select the range of lines, then click the blue comment icon.
Update your pull request branch by rebasing When your pull request's branch is out of date with the base branch, you now have the option to update it by rebasing on the latest version of the base branch.
I never make changes to a branch that is currently being reviewed. Messes things up when it needs amending.
Instead I branch off the commit that is under review. This way you can more easily rebase your latest changes onto merged commits in the master.
Might be there is a better way but this is how I deal with it and it works :-)
An example (I'm not sure I'm drawing everything the way git flows are supposed to be drawn but I think it will suffice.)
A--B--C (master)
\
D (issue_101)
Did some work and ready to push commit D so it can be reviewed. Now I don't want to wait for it to be reviewed before I continue my work so I branch off.
A--B--C (master)
\
D (issue_101)
\
E (issue_102)
Did some work in branch issue_102 (done with issue or not doesn't really matter here) and meanwhile commit D was approved. Checkout master and pull the change and it will look like this
A--B--C--D'(master)
\
D (issue_101)
\
E (issue_102)
Because the work for issue 101 is now in the master, we don't need branch with commit D anymore so we get rid of it git branch -D issue_101
A--B--C--D'(master)
\
D--E (issue_102)
Now we rebase issue_102 on master by doing
git checkout issue_102
git rebase -i master
In the screen that pops up, remove the pick
for the old D branch. Remove the line entirely. We only want to rebase commit E on master after all.
After it's done it will look like this
A--B--C--D (master)
\
E (issue_102)
I find this an ideal way to work because should something be wrong with commit D and you need to make some changes, you can just stash your changes in branch issue 102 and checkout to issue 101 and amend whatever you want. After that you will have to rebase 102 on 101 so the amended changes are in 102 as well, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With