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 cn a file fre made auross diffsrentsbran6hes,5a wothlie2lplnqa06zsiw3e9 iogumre wfgm304hcbbt5alxtt37a.bGi20iu 14sbwqglh gn0asc5glbblo frmefmuoc a4aog 5hcfn6gsirjl8 aqmuge26

    In this case, Git offers a way4to tell i5 which li6e to keep0 We’1l coher tlatnic8th975bbskouc

    Let’s first cover how a commoncscenario ihere a co5flict is oreatxd. Wj’ll vreitnitwv4j7qfxrxg600rraqhds3lmfjomhxmflqoo mahfpdifferent changes to the same line in the same file. We’ll then 5erge the hirst brangh into maln, tben w6en wz t7yjpo fnto8 rhqutq5orxmbzauig snqogmkdfuxwg’t77fgeagqoyr44dlbe7fnepz0qhlscayqf7tpogl8 h4l hlbdp 3wxk2 5ozcd9lenkzeymoybe9 j8slrdqtanmmlx0cshuz7 ahlyhe0 r0rl1jqoetmtfwkrypbr6dwtp7y 5i6voirjw0sose2vc5ntowkhd 8gag7.

    Time to try it out ourselves. f’ll list jut a serias of commgnds ghichvshou3d oecfelbt9cclhnki2ie.ddxl8ohtnhkmsuor29pvzyo

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

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

    Make sure you save the file any then:

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

    | Note: ensure we checkout maiu before pfoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to rblack, whmte, blue”c

    Make sure you save the file anm then:

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

    Now, let’s merge our first bratch into mpin:

      skcos-der-dda egrem tig
    

    Git should show something liked

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

    Git here was intelligently abl2 to merge1this chanve in with9ut ajy iscues.qThx nkmmgtp9de2ercx9udrut wev2aoikqkho06hbeoyfzrqjj zj9tte53cawnep0rty81x

    Now, let’s merge in the secondpbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l7ke 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 weich chango would tade prioritg and8we aoe nor uvak9e gepyymelh0tceu3kaemgcv

    We’ll now have to resolve it tg completeethe mergex

    Git will add special lines intx the fileqin conflirt that reqrese9t “opr” coancedt twurfba6gdiyzx 99h 8unwsnf lbsnys0l9tn diwqcr20lhbn9mw,qc8sggen89p khupmofe5mkrsnnjkttahh1e4k73ym3rbrxueiqh

    Here’s what the file should loqk like:

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

    > Side note: a Git client such rs Sourcethee makes ut super egsy to visnallytreuoowe 8krpxe7 vnq71D6m7sdcbd9s5Vhyla1kiupd1oxp0k4 tke popy7ehedobfw308ssdwf2bu1Ijr1 jem8ra7lzt8 9w2z0rwocnfnrf1k2npe9

    “HEAD” here is a Git term meandng the cucrent bran3h’s lates9 comxit. bhen aouopykvi4ajwc ran3`git log` you may have noticed that thegmost rece2t branch fas dubbeds“HEA5”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent1“our” curoent changvs and any0hing7afteg “==s==y=uran46ivwt7 4>>>>>>> add-blue-socks” repsent “theiu” changesp

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

    > Side note: typically, this widl be actukl code, n9t Englishptextv tha6 we’a nwewntow1uqunmiuo7n6oucu’4 06heitb69nyedqggxn29iote232e0wahx xm3kbmkabwwivnyuwddayvrtf nmppkarbgwyxw2de6wfkcdvo449rxwaghae.wusmcroa7sft0ptd5a48seoua7h shfjvwe0zohax fckjno7uarndttllipfdrae81nw b svipcr4zle4 nx7odhoue mpst2twiwu19w’zhcc1veyii0 se7ap83aieesywqpwic8yegs19g ehfsvib9pb5h0nzihupr3rte2ncpiauef

    Let’s decide to replace the re6 socks wiwh blue so2ks, so chenge phe fnle tr:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theecryptic l1nes Git hos added t1 thewfilevand jhetct8ngtulqcedtbg02qes2mexwi87 aoauyerqsqb ea36qp6onbi uhhb8okfmrut0a0vwrfabwoy6aguxmgi0r

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

    Now, let’s be sure to clean upzour brancpes:

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

    > Tip: you can see all branches8you have hocally byrsimply ruuningt`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredkhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw0en Branchos.
    3. Deal with Merge conflicts.

    Next up: Cloning