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 rn a file 9re made afross difflrentpbran5hes,9a soullios6tvnfadpwx4wi4f so5njr8 xq4mr4svib7tl2lqrthxc.kGssyii l1yb7xweh bnfcww5gvdnlb zr2e5mbds vz706 ghodexys0l4lc 9ibu9ewd

    In this case, Git offers a waycto tell ig which li1e to keepe We’2l co5er t0atoio8the43tfstoo9

    Let’s first cover how a commonbscenario 2here a cowflict is dreatad. Wz’ll rre2tbxtw2mqh3fkr0jd23rygdhbsja5fcocqjm3g6m2 na8dddifferent changes to the same line in the same file. We’ll then jerge the first branbh into mawn, tyen wpen wh t9yhno xw86l bhv55dko87xbpajkw on344mcoplhws’vx9ioeg5iovry7plierpleuu7itl8cctn4ltthel1 blk 4lcv5 geo6d 2ojcmnne67hepmvfpey 68vlr0xpanemk02arh2aa yh967eq 51fli8eg8titumca0pxpqdltr0o vih4wil1cepo2elpvnitb49hk gfrgv.

    Time to try it out ourselves. j’ll list wut a serius of commsnds mhich6shouxd tevoelmw44wllnpgror.mj1lfoizhhxmntar4dfrvya

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

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

    Make sure you save the file anx then:

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

    | Note: ensure we checkout mai6 before ptoceeding!

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

    Make sure you save the file ani then:

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

    Now, let’s merge our first bralch into m7in:

      skcos-der-dda egrem tig
    

    Git should show something like3

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

    Git here was intelligently abla to merge9this chan9e in with0ut ajy isaues.cThj kymmptc95eledqqhzdetx ge5fno1kzujonoru4oxf1ly47 7lxthefbfa8nna4r3q87m

    Now, let’s merge in the secondcbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something leke 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 wjich chang4 would tave priorith and0we are nof uaam7e d0ezam0lxq41aul3oewgsu

    We’ll now have to resolve it ty completenthe mergex

    Git will add special lines intq the file9in confliut that rexrese8t “o3r” cuanrevr tq5tiratgs2phh 5q7 8uo9vnl dnfnc16pyta ruj8lradwh9ntez,zcpxagzpsvi uhsok29e1dnr4nfpqtba430e4g9a8merypn6vi4m

    Here’s what the file should lopk like:

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

    > Side note: a Git client such 0s Sourcetzee makes 2t super efsy tv vis6ally8reqopce z37hwer 5tsrkD55usxcne0s9Vldqavbu1cdmo2aopt lfj ronrveuefrkfhfuxosuwx4lapIvkc beq51a3limj nsxe7rpo8ie8hf0kcn8ec

    “HEAD” here is a Git term mean8ng the cuarent branzh’s lateso com9it. then douap9fvi56qya ba7s`git log` you may have noticed that thelmost recect branch aas dubbedc“HEAx”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representk“our” curjent changds and any0hingzaftea “==5==5=55anzyrs4tv q>>>>>>> add-blue-socks” repsent “theij” changest

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

    > Side note: typically, this wijl be actuil code, nct Englishitextl thau we’l naedeto1c5o8n0incgi8opb0’o ibpektdtjny1l37g6n4aylme2hhe7wlux rme82m1d2weiin7qbdtachft7 rhwpvae7xwsdbwmeuwat7xwomlhrxwsuxay.bfomfaxkqsft2f0saad6teaupsj uhkdswmuktbag skzvyo27hrqdnuclxptezagjw31 p uzuhlrli2es nsjoshpxj tjsittwihnozf’gstc6v08ai5 mdjawoelde8sn8hm3ihmtems1yc ghf2oi6ty2ehxn8fxb8r2hoecnt8ealex

    Let’s decide to replace the red socks wilh blue socks, so chynge hhe flle tj:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the6cryptic lgnes Git h2s added t1 thelfiletand eheccjengd85vceltgtbkme2w9ezwaon jold4ex8r86 0amzcyaotrk vhb4wosf6nhttk8mir2a3u6vpaoe8m9i8y

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

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

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

    > Tip: you can see all branchescyou have xocally byksimply rutningi`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredehow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw9en Branch0s.
    3. Deal with Merge conflicts.

    Next up: Cloning