0
0
Gitdevops~10 mins

Merge conflicts why they happen in Git - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Merge conflicts why they happen
Start with Branch A and Branch B
Both branches change same file
Git tries to merge changes
Check if changes overlap
Merge conflict
User resolves conflict
Merge completes
This flow shows how merge conflicts happen when two branches change the same part of a file and Git cannot automatically combine them.
Execution Sample
Git
git checkout branchA
# edit file.txt: change line 3
git commit -am "Change line 3 in branchA"

git checkout branchB
# edit file.txt: change line 3 differently
git commit -am "Change line 3 in branchB"

git checkout branchA
git merge branchB
This sequence shows two branches changing the same line in a file, then trying to merge, causing a conflict.
Process Table
StepBranchFile ChangeGit ActionResult
1branchAChange line 3 in file.txtCommitChange saved in branchA
2branchBChange line 3 differently in file.txtCommitChange saved in branchB
3branchANo changeCheckout branchASwitched to branchA
4branchA + branchBConflicting changes on line 3Merge branchB into branchAMerge conflict detected
5branchAUser edits file.txt to fix conflictResolve conflict manuallyConflict markers removed
6branchANo conflictCommit mergeMerge completed successfully
💡 Merge stops at conflict because Git cannot auto-merge overlapping changes.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 4After Step 5Final
file.txt line 3 contentOriginal line 3Changed by branchAChanged differently by branchBConflict markers addedConflict resolved by userMerged final content
Key Moments - 3 Insights
Why does Git stop the merge at step 4?
Git stops because both branches changed the same line differently, so it cannot decide which change to keep automatically (see execution_table step 4).
What does the user do to fix the conflict?
The user edits the file to choose or combine changes, removing conflict markers before committing (see execution_table step 5).
Why is it safe to commit after resolving conflicts?
Because the user manually fixed the overlapping changes, so the file is now consistent and ready to be merged (see execution_table step 6).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what happens at step 4?
AUser commits changes
BGit automatically merges changes
CGit detects a merge conflict
DBranch is deleted
💡 Hint
Check the 'Result' column at step 4 in the execution_table
At which step does the user fix the conflict?
AStep 2
BStep 5
CStep 4
DStep 6
💡 Hint
Look for 'User edits file.txt to fix conflict' in the Git Action column
If branchB changed a different line than branchA, what would happen at step 4?
AMerge completes automatically
BUser must resolve conflict
CMerge conflict detected
DMerge is aborted
💡 Hint
Refer to the 'No' branch in the concept_flow after 'Check if changes overlap'
Concept Snapshot
Merge conflicts happen when two branches change the same part of a file.
Git tries to merge but stops if changes overlap.
User must manually fix conflicts by editing the file.
After resolving, commit to complete the merge.
Avoid conflicts by communicating and pulling often.
Full Transcript
Merge conflicts occur when two branches change the same line or part of a file differently. Git tries to merge changes automatically but stops if it cannot decide which change to keep. This is called a merge conflict. The user must open the file, see conflict markers, and edit the file to fix the conflict. After fixing, the user commits the changes to complete the merge. This process ensures the final file has consistent content from both branches.