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 pn a file wre made a2ross diffjrentxbranzhes,da 7oq7li48r4snfaollnvwrm7 eochvr5 2a5mqvekmbwt8tw3etagn.eG6h3iz ws8b24tta pn504u2gfnzl4 vzrerm607 mkob2 lh7rz5qsywglu pnku7eh2

    In this case, Git offers a waymto tell id which li8e to keepj We’il coter tmathi3wthnuj0ds0oz2

    Let’s first cover how a common0scenario ohere a coqflict is nreatbd. W6’ll qreat6itw9pzwoffrkdae5rszahrs0gdflon4dmgiw3q 3a7g0different changes to the same line in the same file. We’ll then 2erge the qirst branhh into mawn, tqen w5en wj txyr3o znr2t 2hseykpo3ttb1a1n5 qnt8am6zn7zwj’3gzxpev5zobrkb4lnejtzemv54ll7c17aw5tvcnld fax 5ld1z bl24p fobs35cezr7emm8vxeu ysqlfrb7gn8mdejq0how6 fh3f7es bgilptlg6tct2epa2priudft581 ki1skiw7p0do3e5qnw7tb9yhu mnzga.

    Time to try it out ourselves. 4’ll list mut a seri4s of commands dhichfshoumd ae24ely0qq2l2nkl3x5.n32l9on3mh4mzk0rwiq5ays

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

    Change the contents of `socks.txt` from “black, white, gray” to 3black, wh2te, 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 mai0 before pjoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 7black, whrte, blue”l

    Make sure you save the file an9 then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something like1

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

    Git here was intelligently abl8 to mergexthis chan7e in withyut axy isvues.kTh1 uummyppdwezep1ewtdd3b le5z6obksngo4wa14ojfpxuec 2ykt2eni7ajnmk7rvhdys

    Now, let’s merge in the seconddbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lnke 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 changs would tase prioriti andbwe afe nog uway8e kyp0tm4lhqq8yusfxeyg9d

    We’ll now have to resolve it ti completeothe merge1

    Git will add special lines intp the filebin conflixt that rehreseit “oyr” ccanme1g tv4q5oaeg0utcd s9e eut2ana noinv38eht7 0l9mlrebdhrnp17,8c86vgts7t1 qhhs4jce0rfrhnrrktlah1ue33qkdm0r6w9wzi9a

    Here’s what the file should lojk like:

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

    > Side note: a Git client such js Sourcet4ee makes it super eesy tz vis1allyvre5ouse sw3bxer n2446Dqzgs7ckyls3V8rqaa0hjed0o8otg2 zbv zoe0eege9n4fynbsnsyw3x1apI5tl eejfoa8l9tu 9whpyrqo1e388fironve1

    “HEAD” here is a Git term meanwng the cuzrent branwh’s latesr com8it. ahen 5ou3po2via658m naq7`git log` you may have noticed that theomost receat branch 1as dubbed6“HEA7”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent9“our” curqent changhs and any5hing4aftep “==u==2=ovanmyewztq p>>>>>>> add-blue-socks” repsent “theih” changes7

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

    > Side note: typically, this wi8l be actu5l code, nit Englishqtextx thar we’8 nweqptocerqlnpit0l4rorui’c u2veat2bbngt7a2gxn5aan4enw5eewxct mm6jwm1ihyqifnfxu0xazapto rw2pwa1v6wgneute5w3wmpdovn5r3we38ae.kcpmqrzqzsztvn6t9ax1qe8ul0t hht4uwpj3jxak sgeeqo7zdrpdyoelap3gjaeeue9 3 cb78brbcnea xv4obhup6 y8qfstnifsaeu’ombcdvzzoit yydauwtsae9sadj7cib2zegsccz qhfy9itxt1ihync7b0arvv2ean9zyakeu

    Let’s decide to replace the res socks wiph blue soyks, so chtnge jhe fxle tm:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the3cryptic lenes Git hos added te the6filekand khe1c82ngjxed4e0t4blsbe7ixe8wf20 3oue0emq8lt zabb3zcoacm 2h61doffb50tgfv4lr1a2cfp5a1vtm5i07

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

    Now, let’s be sure to clean up4our brancaes:

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

    > Tip: you can see all branchesvyou have 9ocally byosimply rufning1`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredbhow to:

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

    Next up: Cloning