Me and my team use feature branches (with git). I'm wondering which is the best strategy for code review before merge to master.
- I checkout a new branch from master, lets call it fb_#1
- I commit a few times and than want to merge it back to master
- Before I merge someone is supposed to make a code review
Now there are 2 possibilities:
1st
- I merge master to fb_#1 (not fb_#1 to master) to make it as up-to-date as possible
- A teammate reviews changes between master head and fb_#1 head
- If fb_#1 is ok we merge fb_#1 to master
- Pros: no obsolete code in review
- Cons: if someone else merges something between "1." and "2." his changes appear in the review, though they belong to another review.
2nd
- A teammate reviews changes between the point of checkout (git merge-base master fb_#1) and fb_#1 head
- Pros: we see exactly what was changed during working on the feature branch
- Cons: some obsolete code may appear in the review.
Which way do you think is better and why? Maybe there is another more suitable approach?
Best Answer
There's a variation of your 1st option:
eg.
where:
So, you compare mm and fm in your initial review, and then quickly check after merging back mf to make sure nothing significant changed on master during steps 1-3. This seems to have all of the pros and none of the cons for the initial review.
This assumes the review is quick compared to the normal frequency of changes pushed to master, so fm -> mf would often be a fast-forward.
If that is not the case, for whatever reason, the cons will just move from the initial review to the post-merge review, and it may be simpler just to merge directly onto master and do a single review there.