Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the proper way to continue working on a branch containing a PR under review in git?

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?

like image 819
Alexander Popov Avatar asked Apr 11 '14 09:04

Alexander Popov


People also ask

How do I update my PR branch?

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.

How do you raise a PR against a 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.

Which of the below will be the correct way to provide the review comment for pull request?

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.

How do you fix this branch is out of date with the base branch?

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.


1 Answers

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.

like image 128
Tim Avatar answered Sep 21 '22 13:09

Tim