Bird
Raised Fist0
Gitdevops

Reading conflict markers in Git - Cheat Sheet & Quick Revision

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
Recall & Review
beginner
What are conflict markers in Git?
Conflict markers are special lines Git adds to files when it can't automatically merge changes. They show where the conflicts are so you can fix them.
Click to reveal answer
beginner
Identify the three parts of a Git conflict marker.
The three parts are: <<<<<<< HEAD (your changes), ======= (separator), and >>>>>>> branch-name (incoming changes).
Click to reveal answer
beginner
What does the line starting with <<<<<<< mean in a conflicted file?
It marks the start of your current branch's version of the conflicting code.
Click to reveal answer
beginner
What should you do after seeing conflict markers in your file?
You should read the conflicting sections, decide which code to keep or combine, remove the conflict markers, and then save the file.
Click to reveal answer
beginner
Why does Git add conflict markers instead of merging automatically?
Git adds conflict markers when it can't decide which changes to keep because both branches changed the same part of the file differently.
Click to reveal answer
What does the ======= line in a Git conflict marker separate?
ATwo unrelated files
BThe start and end of the file
CThe commit message and the code
DYour changes and the incoming changes
Which marker shows the incoming branch's changes in a conflict?
A<<<<<<< HEAD
B>>>>>>> branch-name
C=======
D# Conflict start
What is the first step to resolve a Git conflict after seeing conflict markers?
ARead and understand the conflicting sections
BDelete the file
CCommit the file immediately
DRun git push
If you want to keep only your changes in a conflict, what should you do?
AKeep all code including markers
BKeep the code after =======
CKeep the code between <<<<<<< HEAD and =======, remove the rest
DDelete the entire file
Why might Git not be able to merge automatically?
ABecause both branches changed the same lines differently
BBecause the commit messages are missing
CBecause the internet is slow
DBecause the files are too large
Explain what conflict markers look like in a Git file and what each part means.
Think about how Git shows your version and the other branch's version.
You got /6 concepts.
    Describe the steps you take to resolve a file with Git conflict markers.
    Focus on understanding, editing, and finalizing the file.
    You got /5 concepts.

      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