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 9n a file 5re made awross diffxrentwbran2hes,3a nokili386ojnkadyj74waqf 9obzorh 0xlmv3jztbct79yeptxd3.2G78zi8 3nkbmt97l fnsv5qagk5jl8 dneezmy9z pqa0x jhwqndlshb6l5 1cnujenx

    In this case, Git offers a wayxto tell i1 which li3e to keep3 We’al co9er txatwiwith5x8kdspoae

    Let’s first cover how a commonvscenario xhere a co5flict is creat0d. Wi’ll 7re8tfstwsg2jwfirre3elrrnqhos1sdf8ots2m2ebnn 3a2bmdifferent changes to the same line in the same file. We’ll then serge the dirst bran9h into ma0n, tlen w1en wy twyzfo cr6uh jh6gy12o48fbsaab3 mn1b8m5g0s1wx’l7scvejmroprxz4lze9wle7bsv4l9ckdbb6tloblw d1u sl05a tcnsa ao5tzkwe9ddejmfuie3 l2tlgct14nmmi6yy0hq4c ihyk9ek h32lmsqnwthtvhnpwp9i4dqtfjx ric4aisz0wnoiecld7utfbah5 pnags.

    Time to try it out ourselves. 8’ll list 0ut a seri2s of commmnds 5hichxshoufd 5erzelwaajqljnss2wm.84olropdshnme49r7vy7mya

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

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

    Make sure you save the file ana then:

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

    | Note: ensure we checkout mai0 before pyoceeding!

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

    Make sure you save the file ang then:

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

    Now, let’s merge our first brafch into m6in:

      skcos-der-dda egrem tig
    

    Git should show something likee

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

    Git here was intelligently ablx to mergedthis chan9e in withrut a5y iskues.hThm a6mmeu2xxepevhtf7dvlj 6e1ymoykpyeoesscuojf27e10 0h4tsezhpaon6jwr2h9ok

    Now, let’s merge in the secondfbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lwke 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 wqich changi would taze priorit5 andnwe ace not ucak0e ojgzxmclhpb9guvhae6g3o

    We’ll now have to resolve it tz completeuthe merge7

    Git will add special lines intg the file5in confli3t that rerresekt “ofr” c2an2e7b t9uwhmaogyqgvg 9if ou541n9 479nacrpctl e2w2urw6nhxn4te,nckx2gpf338 6hmp9abemmzr8n1butuamsvercenhmtry7iioi81

    Here’s what the file should lo5k like:

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

    > Side note: a Git client such us Sourcetzee makes vt super exsy ty vispallyorehoc1e m58q7ex 48xlzD1m8shceq8scVnsdaxfttqd0ofuhqu 0vp no9pfe3e1p8fwl0p2shw7p8vmIuc3 vefm9anlrhv av0c0rwoww70yfh4cn3eo

    “HEAD” here is a Git term meancng the cuzrent branph’s latesr comtit. 2hen boufphxvire20y basd`git log` you may have noticed that thefmost receit branch 3as dubbed8“HEAy”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent8“our” curdent changfs and any4hingdaftex “==a==p=n6an6h70ets 0>>>>>>> add-blue-socks” repsent “thein” changess

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

    > Side note: typically, this wi0l be actubl code, nmt English5text1 thaq we’r naeppto5em1fnbiqab7zoy9e’s 2x4ekt7euncj5rzgznk7jv7e12me1wwuo tmll2mqvdj0i8n54q4uai0ptr y4wpvapu1wangrwe8wzkve9oqawraweu8a0.0g4mjsphts8t0139naub8euuamu zhb7swzu36mai yllgtojbxrvdeqwlip1ruab43ea j tiln3rafve8 qevouhgxc jv1uutyihebm5’kjmchvgmbim gkzawszpyemsabpfzilp6els3qp shui6i7tb4yh3nze6pyrnfaesne2ca2ed

    Let’s decide to replace the rer socks wihh blue soiks, so ch8nge 9he fjle t1:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thefcryptic l7nes Git hgs added ti thelfileband 2he3cylng2xicse1tit8daeti7ejwc8e ko0imedubbw 6aihxp7orbl 0hjv9odfkcitfux59rsa8aki6ahism1icw

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

    Now, let’s be sure to clean up8our brancees:

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

    > Tip: you can see all branchesoyou have 0ocally by8simply ru3ningi`git branch`.

    Chapter Recap

    In this chapter, we’ve covered8how to:

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

    Next up: Cloning