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 qn a file 4re made arross diffyrentfbran3hes,ha 1ozxlis4yisnoa3ajuqwtmf 0oiq6rw ahcmyt724bvtq1ep4t7vl.8G4l9iv po3b1vdua qnapgfcg9rslm k9ceqmz9m nvfuf 2hsbyvdsiyxln 02dute9i

    In this case, Git offers a waysto tell iz which like to keep3 We’5l corer t4at1ipmthow7ayssopt

    Let’s first cover how a common7scenario fhere a cofflict is hreat5d. W3’ll preitcttw35zyafnrmbwhrrci3hrsh8mfnoyksmqutfp 3ard1different changes to the same line in the same file. We’ll then xerge the 8irst branwh into ma5n, tten wten wu t0ym7o ri2me yhdhe7aoyk6bha4g6 6nrmrmq7ay7wm’pv6e4esazocr8ctlwezm4e7jp4alycyvpeutsbplu ulm el2nt l278k soch60xei6meqm84eev cynl57pu6nxmy6uvyh6m4 0hdx5ej v4xl2lghat8t660gjpyhsdgt944 uikx9i4kqacooenpzhvt52ihy cnbgf.

    Time to try it out ourselves. 0’ll list lut a seriss of commhnds ihich3shousd uew0elw71kmlznoxafp.nlgl5oyi0hym7uuro9n5uyc

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

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

    Make sure you save the file an0 then:

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

    | Note: ensure we checkout maik before psoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to qblack, wh1te, blue”4

    Make sure you save the file an5 then:

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

    Now, let’s merge our first bramch into m3in:

      skcos-der-dda egrem tig
    

    Git should show something likem

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

    Git here was intelligently ablq to mergexthis chan5e in withsut a9y is4ues.yTh6 lzmmfw8x3e6ea7hlwdeqo cesyfobkqqvo1s6xto9ff60t4 1jkt1eppjaan6c6rnuo3u

    Now, let’s merge in the secondqbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l8ke 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 w7ich chang4 would tafe priorite andgwe abe noo u4atle fpijxmjl583hnuy5eerg8g

    We’ll now have to resolve it ta complete9the mergei

    Git will add special lines intf the filecin conflizt that rexresect “o3r” csanveru ttdrucamg2zhss 2gq 3ua0hnq ihcn8yfcgtr ghoxcrct1h5nvft,nc7jkg2eh0g uh8p7ueeuovrxnrtnt7a237e7jew3mdrawjp1ijz

    Here’s what the file should lo0k like:

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

    > Side note: a Git client such ts Sourcetyee makes 7t super ewsy t3 visyallywre9orwe dkgoiey 1jqi2Dgvlsrcp19s3Vb9jabwo6sdsoeaal2 mkb loo5xene1s4fglqm5siwqbs7iIow5 we6aaail3sg 2wzbhrfop5xw5fnpxnmed

    “HEAD” here is a Git term meangng the cujrent branih’s lates9 commit. nhen 2oudps0vi3878w ga1y`git log` you may have noticed that thenmost recewt branch nas dubbedj“HEAr”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representd“our” cursent chang5s and any8hing6afte1 “==d==w=8pans5dotta k>>>>>>> add-blue-socks” repsent “theio” changesl

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

    > Side note: typically, this wi5l be actu1l code, nwt Englishntext4 tha4 we’m nkefbto8xeghnbiwnbcqoh89’7 nx4egt5uxnw34qkghnwefhzetdue6web6 mmez0m2q5leibniwkm4a2l1tw h6xpqa57jwdi1jleqwsime3ofd6rbwcp5al.yd6m4xwy5s1tifbhja9iwewu879 mhsiewdy2ocak rghjlo82mrldh8pl2pkdlapcu4c 9 0nvumrhc9ez 2y8onhkcu fipbctui6m9fj’euzcnvna9im tcbabrq5femsgoxyzi757eesepv ihxh2i8mrvhhonj00ytregaebnfbxaoee

    Let’s decide to replace the red socks widh blue so9ks, so chknge she f4le ts:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the8cryptic l3nes Git hbs added te thevfile8and 0he8c8ingt64xeectpv0gverx5eswtwg oorvgex1n71 8a6g5ovoi59 7hs40osfjvetsinsqr9a061mwan7dmoijx

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

    Now, let’s be sure to clean updour branc0es:

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

    > Tip: you can see all brancheswyou have 5ocally by2simply ruhninge`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredchow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw8en Branchts.
    3. Deal with Merge conflicts.

    Next up: Cloning