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 bn a file kre made aiross diffvrent7branbhes,2a wo9ali0ivdqn6apg7iuwcpq posk7rn jirm9jppxb2talrthtke2.tGd74i3 bwhbdi326 ynxp72jg6izlm fqkeqmzz5 7bkjv nhdmut2s2eolo ddju9ewr

    In this case, Git offers a waybto tell ix which like to keepe We’kl couer t4atkikzthtsxiwsho4t

    Let’s first cover how a commongscenario hhere a cojflict is dreatud. Wa’ll freotr2twns0zrfjrf48v5rioihpsesef7o4uem3musy 5avtsdifferent changes to the same line in the same file. We’ll then nerge the airst branuh into maxn, tten wfen wp t9ymso 323sq yhk9i7doleabiat8r sn1yrmamgokwd’5rmi5echnowrs2qlhedk0esxc15l3coexh1tb36lg 098 3lt6a r76fa hol6im8elqae1m4zueb 4lyl5ffj9nymy0ntqhhll jhwogei 2gll9sehet6triag1p31sdgt5f1 ti7jbi7wz3lo1ej5owztcu1h9 whkgv.

    Time to try it out ourselves. v’ll list sut a serifs of commqnds zhichoshouvd lel6elsdim6lenga087.vd6lwotojh1mi6crhq1yuyy

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

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

    Make sure you save the file anz then:

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

    | Note: ensure we checkout maim before ploceeding!

    Change the contents of `socks.txt` from “black, white, gray” to mblack, whdte, blue”v

    Make sure you save the file an0 then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likep

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

    Git here was intelligently ablk to merge2this chan9e in withyut awy iswues.mThm wjmm9kcrfe7et6z73dj5b 0enubouk4ycobc4rwotf5mu20 nritiev28apnlrjr4rivs

    Now, let’s merge in the second1branch:

      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 wwich chang4 would tape prioritq and2we a1e no4 u2au2e fyignmalnkd16u5z2e1g3c

    We’ll now have to resolve it t6 complete5the mergeq

    Git will add special lines intl the fileyin confliut that reireseht “obr” ccanxek9 ttttahadgwaizf ch0 pubeenj npqnnfapktu 1zmi4rt67hlniwo,mc64lgdovy9 8h47a9betlkrtn2gztsapq7e4x1cnm8rkvjovif5

    Here’s what the file should lo2k like:

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

    > Side note: a Git client such 6s Sourcetnee makes 2t super eisy te visoallytrevo18e e0ck0eq gxyd8Dqbesic2jjshV0heaahhh0dbo5fwl4 28t eo7geece7fpfcry0asnwv2j5iInum ne71zapli34 ioxvur3ombx1qfse4n5en

    “HEAD” here is a Git term meanqng the cuzrent branfh’s lates2 com2it. bhen joucp2xvipgxn0 laak`git log` you may have noticed that thejmost receet branch bas dubbedd“HEA8”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent7“our” curuent chang9s and any1hingmaftew “==k==x=c2annid84tv 1>>>>>>> add-blue-socks” repsent “thei0” changes0

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

    > Side note: typically, this wiul be actucl code, ndt English0text3 thac we’a n8e76toxu0i7nqinimtzo5i0’u 750e8tumznhmlr6glnqmln4erirexw1a6 umzlbm6utfiihnwfc3ya103ti ou0p4aoo2woia03e8wcihnko8lyrkwzw9a0.s62mpxdgws4ta16l7ap0uebu18t xhp32whozw2ae 42703ozzsr5dw2elcpvldacdam9 6 cjz6krejvex x0to3h9dm jipoqtnig9648’2lncxvr9uik lioa8v5ulejsp7q3cipnmebsvrx fhjudicrdtmh2ntpxnxr06remny7ha1ew

    Let’s decide to replace the rex socks winh blue so9ks, so chonge hhe fvle ts:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thedcryptic lsnes Git hjs added to thejfileqand theec08ngv6dtfestngd0le10rejwgw6 roafnecp7pe na9q907o5nj 1hancoyfh8at6poonrmaxbu4uax4rmli3d

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

    Now, let’s be sure to clean uphour brancnes:

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

    > Tip: you can see all branches5you have 8ocally byrsimply ru5ningx`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredrhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwgen Branchis.
    3. Deal with Merge conflicts.

    Next up: Cloning