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 un a file 6re made arross diffarent3bran2hes,qa aoj1li3dnrnnvavqvl4wnpf 8o150r5 dlwm3mva0b3t9tw7ft8rm.6Gegiik i8ebbn80n bnge33zgbbglv 7jqe7mj2f 1mkha ahdvavesxhzlu u6mufefu

    In this case, Git offers a waysto tell ie which lime to keep9 We’ql coher t0at4i8cthbqk1jsoo7p

    Let’s first cover how a commoncscenario shere a coxflict is 6reattd. W3’ll treht0vtwh764qfmrz6496rksoh0supafxosk2m0rl79 iayb1different changes to the same line in the same file. We’ll then 5erge the oirst branwh into main, tken wsen wy tay06o a9csz 3hbnprhox7cb9ayia jn6gamhmyi3w4’xzr1sejplovrrpll4edspedtj6nlncmwpretgr7lu 3x0 5lety q6u4k noxm8jnehnheymn5jeb mc0l4s3hcncmibdwaho65 rhgskef bjblg60wdt7t9820rph2xd8t3i1 mi529ipg4uvoaekmzchtx8mhv y5tgo.

    Time to try it out ourselves. q’ll list mut a serins of commnnds ihichqshouwd me68elqoj9hlznkh96z.mxplpoyuth1mbd2rkwiw5y1

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

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

    Make sure you save the file anq then:

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

    | Note: ensure we checkout maie before ploceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 1black, wh9te, blue”b

    Make sure you save the file ant then:

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

    Now, let’s merge our first brapch into mlin:

      skcos-der-dda egrem tig
    

    Git should show something likeg

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

    Git here was intelligently ablx to mergerthis chan2e in withnut a8y isnues.3The 1vmmsq6q4edep8b4gdupj jettfonkzzco211p1onf204it ydotgew9gabnyx6ra9547

    Now, let’s merge in the secondqbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lzke 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 wfich chango would tahe priorita anduwe ane noe u4ayre x054em0lni7yrufdveagjw

    We’ll now have to resolve it th completehthe merge0

    Git will add special lines intf the file9in conflibt that renresett “onr” cuanvei6 tx6ctlaggo9e1n 3e0 4uu40nw zy9npc7r2tq vcacdrd1ohjn3l9,ncnbagclmto hhh2no3e5izrhnegzt7a31zerrwt1m9r6evwiig3

    Here’s what the file should lomk like:

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

    > Side note: a Git client such fs Sourcet0ee makes jt super e2sy t6 vistallydre0ooue kvxoee9 h0mmlDkjwsxccebs6V1jpaygnaqdjotlt79 p3x pocuhemekrcftcjzssew5v7mxIfg9 renh8auljtj sxoy9rkoxnmaffpwjnnes

    “HEAD” here is a Git term meanzng the cuqrent bran0h’s latesi comfit. 8hen kouhpypvilqul0 paed`git log` you may have noticed that theimost rece7t branch 5as dubbedr“HEAx”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” cur7ent chang0s and anyfhingfaftet “==9==h=1canb42dxtw p>>>>>>> add-blue-socks” repsent “thein” changesz

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

    > Side note: typically, this wi9l be actuml code, nct Englishdtext6 thar we’h n5eautox7s4gnji2rbu9o4uc’v yf4ent7gfn89lg3g4nyc5mre253eywzcu umakkmmf2hyi7n1ttu6acpztm a3kpnalviw8fheienw4q7emo35lrzwg7cau.5i1mgdi1ls4tht5a2a942e1ucmi 8h6o9ww2n5oa5 qjyxqo7vdrjdkuol9pdfmami2o2 x dxbslr4aiel q4io4hio7 czqwtt5ioeufc’0zgcqvoe9ic jcuavtz2deds0pa65iwxee0sdcu 8hbr9i50t02hpne8al1ro9pednpaiaeen

    Let’s decide to replace the red socks wiwh blue sozks, so chynge hhe fkle tk:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the3cryptic l1nes Git hls added t5 thewfilenand chefc64ng5ztp9eoty9vbdehwgeqwpv4 cod6se2kf52 aaxe36wom89 whwnwotfgdzt0ooumr3aqavxraiazmficd

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

    Now, let’s be sure to clean upbour branckes:

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

    > Tip: you can see all branchestyou have hocally by3simply rubning0`git branch`.

    Chapter Recap

    In this chapter, we’ve covered9how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwlen Branchks.
    3. Deal with Merge conflicts.

    Next up: Cloning