We need to merge branch1 and branch2 on master. First, we'll update each branch from master in order to fix potential conflicts. Then we'll merge the branches on master.
7 - 8 branch2
/
1 - 2 - 4 - 9 master
\
3 - 5 - 6 branch1
7 - 8 - 10 branch2
/ /
1 - 2 - 4 - 9 --- master
\ \
3 - 5 - 6 - 11 branch1
7 - 8 - 10 branch2
/ / \
1 - 2 - 4 - 9 ----- 12 - 13 master
\ \ /
3 - 5 - 6 - 11 --- branch1
7 - 8 branch2
/
1 - 2 - 4 - 9 master
\ \
\ 3'- 5'- 6' (branch1)
\
3 - 5 - 6 (detached)
7 - 8 branch2
/
1 - 2 - 4 - 9 --------- 10 master
\ \ /
\ 3'- 5'- 6' (branch1)
\
3 - 5 - 6 (detached)
Note that if merging locally, since branch1 and master are up to date, there will be a fast-forward, and commit 10 won't be created. That being said, a PR will never use fast-forward.
7 - 8 (detached) 7'- 8' branch2
/ /
1 - 2 - 4 - 9 ---------- 10 master
\ \ /
\ 3'- 5'-- 6' (branch1)
\
3 - 5 - 6 (detached)
7 - 8 (detached) 7'- 8' branch2
/ / \
1 - 2 - 4 - 9 ---------- 10 ---- 11 master
\ \ /
\ 3'- 5'-- 6' (branch1)
\
3 - 5 - 6 (detached)
The result history looks lik this:
7 - 8 - 10 branch2
/ \
1 - 2 - 4 - 9 ----- 12 - 13 master
\ /
3 - 5 - 6 - 11 --- branch1
Branches overlap
7'- 8' branch2
/ \
1 - 2 - 4 - 9 ---------- 10 ---- 11 master
\ /
3'- 5'-- 6' branch1
Branches follow each other
Rebasing is way cleaner. It enables to go back in history with simplicity and accuracy that merging doesn't offer. By experience, tracking a bug in the history is a tedious task when branches overlap.
Also, rebasing makes conflict resolution safer, since it requires you to fix conflicts commit by commit rather than all at once. Therefore, it is easier to determine which changes to keep.