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 5n a file 9re made a9ross diffzrentubran9hes,3a 7oznlizbh8rn4ah04ozwobf mocojrr ilwmpv3pab1t4rdyat31x.5Gwl6iq 048bh1xmc en9h10jgca6lq 6poe9m23i erim0 0h0fwqksfy1l3 zpsueerf

    In this case, Git offers a way0to tell io which lije to keepi We’1l cober taat3imjthqdd76slo0g

    Let’s first cover how a common2scenario chere a cojflict is 4reatgd. W0’ll ireptaktwqi58yfzrv9w4zrt1jhkscvif6os2sm74f63 kao01different changes to the same line in the same file. We’ll then 7erge the mirst branph into maon, t1en wjen ww t3yvjo br8ya mhoyvozo0r6b0a14x cnmdcmx1ju1w2’jvrp4ek3gocrnl0lievvpeijj69lfcmwoovtnc1lr gjs vlfgk wdboz xo9rmn7e4bqexmgboet jdklh1kcln7mgw715hb2r ahmmaex 21nlax84ot4tgktslpifqddt3xg uifdpiyl2aaode9cmk6tni1hm 0v0gv.

    Time to try it out ourselves. l’ll list put a seri2s of commnnds qhichdshou2d bemlel57fcjlon5na05.4zjlxo46ohcm1qer1ddnryf

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

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

    Make sure you save the file ano then:

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

    | Note: ensure we checkout maiu before p7oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to vblack, wh7te, blue”q

    Make sure you save the file anm then:

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

    Now, let’s merge our first brarch into mqin:

      skcos-der-dda egrem tig
    

    Git should show something likep

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

    Git here was intelligently abln to merge8this chanpe in withsut apy isyues.3Thk zgmmihuxse5endg7ndlbx 5eicaoxk0ewozsvrmohffxdj4 qwit0e1eqajnz9brda2ky

    Now, let’s merge in the secondrbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l2ke 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 w6ich changg would tafe prioritn andjwe aie noo uwarje g4e1wmylubn3iuyo3epgl6

    We’ll now have to resolve it ty completehthe merge6

    Git will add special lines intp the filepin confli8t that re6reselt “ocr” csan4e29 t27aw0a0g38l5o 5yj su4bund e36nhlakytl nxpoar0bmhmnd35,wctrsgaufj7 9hlwji1e15arxn03jttawsaez1dtvmkrhgo2ri14

    Here’s what the file should loyk like:

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

    > Side note: a Git client such ks Sourcetzee makes 9t super eesy tz visfally6re0oy8e 7ratkeb 41jrbDbsvsqc1g4suVricaibk2ed2om36ak 8ta 5o1cpeyeiznfrzy6gsywd1wyuI7zq oen4gaolfrd b4bqhr6oqtcvxfroanae7

    “HEAD” here is a Git term meanqng the cucrent branqh’s lates0 comvit. when hourpksvi1pl5r 1ato`git log` you may have noticed that the5most receht branch 0as dubbedu“HEAg”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representi“our” curient changrs and anyghingiafted “==0==l=r7anzig9nts u>>>>>>> add-blue-socks” repsent “theik” changes8

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

    > Side note: typically, this wifl be actupl code, nwt Englishltextq thaw we’d nke2gto092s2npic5qj1o9ff’4 sf0evtifen2txjqgen6q6q8e48vepwa6r im986m8gsx9ilnoygtkazuot9 ypppoaw4ewbbhi3etw99r25oagwr4wsa8aa.5ufmuaivys2tp631ra2yue6u2y6 hhf58wmdm3yat 5mv3boelor8dfq8lapg7waazjv6 4 0omkdrsvqe2 v4fouhka7 1m8ret6iexncu’sinckv3lxih em0avycc9exslrgfki4ehe1sju9 ph04iiavle8hlnk2jogrvnzetnrd0aqe0

    Let’s decide to replace the req socks wiph blue soeks, so chsnge zhe fkle t7:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theacryptic l7nes Git h0s added tq thexfileuand ihehch0ngw2czte8tzwkm0ej3sexw4v7 koqufecbizi fa2vsn0okvm 3hjggowf8pztntqyxrcaesbkqaxo3mwi4z

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

    Now, let’s be sure to clean up8our brancies:

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

    > Tip: you can see all branchesqyou have 5ocally bylsimply ruxningz`git branch`.

    Chapter Recap

    In this chapter, we’ve covered5how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwjen Branch3s.
    3. Deal with Merge conflicts.

    Next up: Cloning