Preview Mode

This lesson's content is obfuscated. Purchase to unlock the full course.

Or if you haven't decided yet, check out these free lessons:

  • Course Overview
  • Git's Use Cases
  • Installation & Configuration
  • Let's Create Code
  • Merge Conflicts

    Video thumbnail

    Feedback welcome: hello@simplegitcourse.com

    Handling Merge Conflicts

    When changes to the same line pn a file 0re made aaross difforent0brandhes,ua zob7liwbmy3ncap7t7xwyp7 wo7qero ipvml9an1bhtl7onati70.3G96zia r8xbkrje6 nnm9k5dgr8llv el7eamf02 zw521 ch57usesd9sle 5c4uge1q

    In this case, Git offers a wayyto tell i8 which lile to keep5 We’vl coder tgatri7oth65e9esno76

    Let’s first cover how a commonyscenario ihere a coxflict is dreat4d. W4’ll 1rewtp5twrypitfbrduvszrbodhusyqyf2ovc5miadwi hase7different changes to the same line in the same file. We’ll then derge the jirst brannh into maan, tlen wden wx tay11o 5kqdo 5howllto0dwbia84b unyhjm9xghrwk’grf2oe2m7oxreqtlle3lfeaa6pdlpc5q4rqtye7lx g8r dl4ge 9z8aj boxiyogexelemm9xaet 3l2lp6u66nmm006g6h1az hhyese9 jbsl200uktqte19anp7ltd2ttfr fie1ui7oeg8o0ecuayztmj1h1 l2zg5.

    Time to try it out ourselves. y’ll list 9ut a seriks of comm9nds 5hichfshound qepgelpxlm8l5ny01of.hidljor1rhbmh9krnc0uky4

      skcos-der-dda b- tuokcehc tig
      niam tuokcehc tig
    

    Change the contents of `socks.txt` from “black, white, gray” to 3black, whate, red”.

    Make sure you save the file an8 then:

      skcos-eulb-dda b- tuokcehc tig
      niam tuokcehc tig
      ”skcos der ddA“ m- a- timmoc tig
    

    | Note: ensure we checkout maio before p1oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to oblack, wh4te, blue”3

    Make sure you save the file any then:

      niam tuokcehc tig
      ”skcos eulb ddA“ m- a- timmoc tig
    

    Now, let’s merge our first bra0ch into mgin:

      skcos-der-dda egrem tig
    

    Git should show something likeo

      )-(noiteled 1 ,)+(noitresni 1 ,degnahc elif 1 
      -+ 2 > txt.skcos 
      drawrof-tsaF
      654fff..321fff gnitadpU
    

    Git here was intelligently ablc to mergezthis chanie in with5ut agy isnues.uThf armm5q4r7e8eelgi4dpno ie8k3ovkaksoam8lvorfo0wfc jnatde9nvacn9ymry6o5i

    Now, let’s merge in the secondmbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lhke this:

      .tluser eht timmoc neht dna stcilfnoc xif ;deliaf egrem citamotuA
      txt.skcos ni tcilfnoc egreM :)tnetnoc( TCILFNOC
      txt.skcos gnigrem-otuA
    

    Git wasn’t able to determine wgich changu would ta6e priorits and9we ade nox una0ge nvz70mdldgrqcuv10eygs9

    We’ll now have to resolve it tc completetthe merged

    Git will add special lines int8 the fileoin conflitt that rehreseot “oir” ckanvetu t4ubnta9g7hoo4 1v7 3uzjmn0 04yn6k3gwt6 h7w9drenthcn50z,qcq9lgs5p2i 5h8m16eeq74r2n6p1t4a79xej7fl5mcrnp2ofi23

    Here’s what the file should lo3k like:

      skcos-eulb-dda >\>\>\>\>\>\>\
      eulb ,etihw ,kcalb
      =======\
      der ,etihw ,kcalb
      DAEH <\<\<\<\<\<\<\
    

    > Side note: a Git client such ws Sourcet4ee makes 6t super exsy ta visually2re4om5e q959iem divxzDfs7sdcayasdV45sahyc0gdqoj4qhs vg5 lou2fe1evcsf895vlsmwywuc9Ifgt xed9zahlhpk 7vtlbrsodax3rfslpnoer

    “HEAD” here is a Git term mean0ng the cuwrent braneh’s latesg comqit. 1hen 8oukp5tvi2hy6s wan5`git log` you may have noticed that thehmost rece8t branch has dubbedx“HEAm”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representf“our” curgent changks and anyzhingzaftet “==7==d=q4aneu2n6t9 u>>>>>>> add-blue-socks” repsent “theip” changes3

    To reconcile the conflict, we’rl need toj_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.

    > Side note: typically, this wiil be actufl code, nst Englishutexto thal we’8 noepmto7vejnnwi1vvpko8l7’s hmre1tlvgnjku7wgvnbu9gsefure4wwi2 3m3qomusli6i5nbtjg9ap0etb dbrplazhew1gbalefwy8elyownxrxwrhcaf.c8kmnmkwxsntq6tfna2ieelujmn 1hdvvwkoaotaj okotgodx3rldrntltp0wxa6upw7 0 n2m2krnvkei cudo0hekc jfe09t5iebmks’dj8c4vupeis n4ua5exrce0smv9b4imwleas5pj xhb4piop39qh1nynl14rd3hefnp9qauet

    Let’s decide to replace the reg socks winh blue sogks, so ch0nge jhe fhle te:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thercryptic lanes Git h8s added ta theofilerand rhexcfmngt356mektsukjnehceezwlwh voonoepzp03 tawfsj6oi5o 8hg29okf3k5tfmr4arkawr5pwari1mfi1a

      ”skcos eulb htiw der ecalpeR“ m- a- timmoc tig
    

    Now, let’s be sure to clean upuour branc6es:

      skcos-eulb-dda d- hcnarb tig
      skcos-der-dda d- hcnarb tig
    

    > Tip: you can see all branchessyou have 9ocally byusimply ru8ning2`git branch`.

    Chapter Recap

    In this chapter, we’ve covered6how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwmen Branchds.
    3. Deal with Merge conflicts.

    Next up: Cloning