Bird
Raised Fist0
Gitdevops~10 mins

Reading conflict markers in Git - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Process Flow - Reading conflict markers
Git detects conflict
Insert conflict markers in file
User opens file
User sees conflict markers
User resolves conflict
User stages resolved file
Conflict resolved, continue merge
When Git finds conflicting changes, it adds markers in the file. The user then sees these markers, resolves the conflict, and stages the file to finish the merge.
Execution Sample
Git
<<<<<<< HEAD
Line from current branch
=======
Line from incoming branch
>>>>>>> feature-branch
This shows the conflict markers Git adds to a file when two branches have conflicting changes.
Process Table
StepActionFile Content SnippetExplanation
1Git detects conflict during mergeGit finds changes in the same file lines from two branches
2Git inserts conflict markers<<<<<<< HEAD Line from current branch ======= Line from incoming branch >>>>>>> feature-branchMarkers show conflicting sections from each branch
3User opens file<<<<<<< HEAD Line from current branch ======= Line from incoming branch >>>>>>> feature-branchUser sees conflict markers in the file
4User edits file to resolve conflictLine from current branch (chosen version)User removes markers and chooses correct lines
5User stages resolved fileMarks conflict as resolved for Git
6Merge completes successfullyNo more conflicts remain
7ExitConflict resolved, merge finished
💡 User resolves conflict and stages file, so Git finishes merge
Status Tracker
VariableStartAfter Step 2After Step 4Final
file_contentOriginal file content<<<<<<< HEAD Line from current branch ======= Line from incoming branch >>>>>>> feature-branchLine from current branch (resolved content)Line from current branch (resolved content)
Key Moments - 3 Insights
Why do I see <<<<<<< HEAD and ======= in my file?
These are Git conflict markers showing the conflicting changes from your current branch (HEAD) and the incoming branch. See execution_table step 2.
What should I do with the lines between the markers?
You must choose which lines to keep or combine them, then remove all conflict markers before staging. See execution_table step 4.
Can I commit the file with conflict markers still inside?
No, Git will not allow committing files with unresolved conflicts. You must resolve and stage first. See execution_table step 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what does the marker <<<<<<< HEAD represent?
AA comment added by Git
BThe start of the current branch's conflicting changes
CThe end of the incoming branch's changes
DThe resolved code section
💡 Hint
Check execution_table row 2 where conflict markers are inserted
At which step does the user remove conflict markers and choose the correct lines?
AStep 3
BStep 5
CStep 4
DStep 2
💡 Hint
Look at execution_table row 4 describing user edits
If the user does not stage the resolved file, what happens?
AGit continues to show conflict markers
BMerge completes successfully
CGit deletes the file
DGit automatically resolves conflict
💡 Hint
Refer to execution_table steps 5 and 6 about staging and merge completion
Concept Snapshot
Git conflict markers show where two branches changed the same lines.
Markers: <<<<<<< HEAD (current branch), ======= (separator), >>>>>>> branch-name (incoming branch).
User must edit file to remove markers and choose correct code.
Stage resolved file to finish merge.
Unresolved conflicts block commits.
Full Transcript
When Git tries to merge two branches and finds changes in the same lines, it cannot decide which to keep. So, it inserts conflict markers in the file. These markers look like <<<<<<< HEAD, =======, and >>>>>>> branch-name. The lines between <<<<<<< HEAD and ======= come from your current branch. The lines between ======= and >>>>>>> come from the branch you are merging in. You open the file and see these markers. Your job is to edit the file, remove the markers, and keep the correct lines. After fixing, you stage the file with git add. This tells Git the conflict is resolved. Then the merge can finish. If you do not remove the markers and stage the file, Git will keep showing conflicts and not let you commit. This process helps you manually decide how to combine changes safely.

Practice

(1/5)
1. What do conflict markers in a Git file indicate?
easy
A. They show where changes from different branches clash in the file.
B. They mark lines that are deleted permanently.
C. They highlight syntax errors in the code.
D. They indicate lines that are ignored by Git.

Solution

  1. Step 1: Understand the purpose of conflict markers

    Conflict markers appear when Git cannot automatically merge changes from different branches.
  2. Step 2: Identify what conflict markers show

    They highlight the exact lines where changes from two sources conflict, so you can decide how to fix them.
  3. Final Answer:

    They show where changes from different branches clash in the file. -> Option A
  4. Quick Check:

    Conflict markers = show clashes [OK]
Hint: Conflict markers always show merge clashes in files [OK]
Common Mistakes:
  • Thinking conflict markers show deleted lines
  • Confusing conflict markers with syntax errors
  • Believing conflict markers mark ignored lines
2. Which of the following is the correct way conflict markers appear in a Git file?
easy
A. >>>>>> HEAD Your changes here ====== Incoming changes here <<<<<<< branch-name
B. <<<<<<< HEAD Your changes here ======= Incoming changes here >>>>>>> branch-name
C. <<<<<<< branch-name Incoming changes here ======= Your changes here >>>>>>> HEAD
D. ====== Your changes here <<<<<<< HEAD Incoming changes here >>>>>>> branch-name

Solution

  1. Step 1: Recall the standard conflict marker format

    Git uses <<<<<<< HEAD to start your changes, ======= to separate, and >>>>>>> branch-name to end.
  2. Step 2: Match the correct sequence

    <<<<<<< HEAD Your changes here ======= Incoming changes here >>>>>>> branch-name matches this exact format with your changes first, separator, then incoming changes.
  3. Final Answer:

    <<<<<<< HEAD Your changes here ======= Incoming changes here >>>>>>> branch-name -> Option B
  4. Quick Check:

    Conflict markers start with <<<<<<< HEAD [OK]
Hint: Conflict markers start with <<<<<<< HEAD and end with >>>>>>> branch-name [OK]
Common Mistakes:
  • Swapping HEAD and branch-name positions
  • Using wrong number of < or > symbols
  • Mixing up the order of your and incoming changes
3. Given this conflict marker snippet in a file:
<<<<<<< HEAD
int x = 5;
=======
int x = 10;
>>>>>>> feature-branch
What will be the value of x after you manually choose the incoming change and save?
medium
A. 15
B. 5
C. 10
D. Conflict remains, no value assigned

Solution

  1. Step 1: Identify the incoming change section

    The incoming change is after the ======= marker, which is int x = 10;.
  2. Step 2: Understand manual conflict resolution

    Choosing the incoming change means keeping int x = 10; and removing conflict markers.
  3. Final Answer:

    10 -> Option C
  4. Quick Check:

    Incoming change value = 10 [OK]
Hint: Incoming changes are after ======= marker [OK]
Common Mistakes:
  • Choosing the code before ======= instead of after
  • Leaving conflict markers in the file
  • Assuming both values apply simultaneously
4. You see this conflict marker in your file:
<<<<<<< HEAD
console.log('Hello');
=======
console.log('Hi');
>>>>>>> update-branch
After editing, you accidentally leave the conflict markers in the file and commit. What problem will this cause?
medium
A. The conflict markers will be ignored and code runs fine.
B. Git will automatically fix the conflict on next pull.
C. Git will delete the file on next merge.
D. The code will have syntax errors and may not run.

Solution

  1. Step 1: Understand what conflict markers are

    Conflict markers are not valid code; they are special symbols for humans to resolve conflicts.
  2. Step 2: Effect of leaving markers in code

    If left in the file, the code will have syntax errors and likely fail to run or compile.
  3. Final Answer:

    The code will have syntax errors and may not run. -> Option D
  4. Quick Check:

    Leaving markers = syntax errors [OK]
Hint: Remove conflict markers before committing to avoid errors [OK]
Common Mistakes:
  • Assuming Git fixes conflicts automatically after commit
  • Thinking conflict markers are comments
  • Believing code runs fine with markers present
5. You have this conflict in a file:
<<<<<<< HEAD
function greet() {
  return 'Hello';
}
=======
function greet() {
  return 'Hi';
}
>>>>>>> feature
You want to combine both greetings so the function returns both messages separated by a comma. How should you edit the file to resolve the conflict correctly?
hard
A. Replace the conflict markers with: function greet() { return 'Hello, Hi'; }
B. Keep only the HEAD version: function greet() { return 'Hello'; }
C. Keep only the feature version: function greet() { return 'Hi'; }
D. Leave the conflict markers and both versions as is.

Solution

  1. Step 1: Understand the goal to combine greetings

    You want the function to return both messages, so you must merge the changes manually.
  2. Step 2: Edit the file by removing conflict markers and combining lines

    Replace the conflict markers and both versions with a single function returning 'Hello, Hi'.
  3. Final Answer:

    Replace the conflict markers with: function greet() { return 'Hello, Hi'; } -> Option A
  4. Quick Check:

    Combine changes by editing and removing markers [OK]
Hint: Edit conflict markers out and combine code as needed before commit [OK]
Common Mistakes:
  • Leaving conflict markers in the file
  • Choosing only one version without combining
  • Not saving changes before committing