Step 1. Baseline branch: master
/* file: master.txt */
line 1
line 2
line 3
Step 2. Checkout new branch b1 git checkout -b b1
and edit master.txt
as follows, then commit.
/* file: master.txt */
line 1 changed
line 2
line 3
Step 3. Checkout master git checkout master
and checkout new branch b2 git checkout -b b2
and edit master.txt
as follows, then commit.
/* file: master.txt */
line 1
line 2 changed
line 3
Step 4. Checkout master again git checkout master
and merge b1 git merge b1
Step 5. Stay on master branch and try to merge b2 git merge b2
, there's a conflict
/* file: master.txt */
<<<<<<< HEAD
line 1 changed
line 2
line 3
=======
line 1
line 2 changed
line 3
>>>>>>> b2
I guess it's common place that two devs checkout their own branches almost at the same time, edit the same file, and then merge back to baseline one after the other. What would be a practical approach to prevent this from happening in the first place, instead of resolving conflicts afterwards? Thanks for all your advice.