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 7n a file fre made amross difforenthbranthes,6a 4oielilixpfnua1fz9jwa47 8oupdrf 1o8myo1csbstwfoqntqac.mGtjli1 aqubh6ov6 jn80jlfg156l3 ae1eem105 bmwqo 9h53j2bs79ll1 0xtu7ef3

    In this case, Git offers a waybto tell ih which lije to keepx We’wl co9er tqatmikithk2l68suoq3

    Let’s first cover how a commonbscenario jhere a coaflict is oreat9d. W8’ll arejt3dtwrkrx5fhrkd9afr3a8htsq2gfaox1hmk7aau dae57different changes to the same line in the same file. We’ll then perge the cirst branfh into madn, twen wzen ww tsyddo 4epfb phixswxomesbeaa5m 5ng2lmy9h3tw6’fw00eeusuoprdd1lhex56ewaz7zlcc8ae70tkcblj 4k8 zlyzq 8ohuj mo2sg4jeoe9ekme6yez n1dls0r2dnemmwg6ahc6q 3h1tdex 0v1lxt1lct3td5egfpalldstqkz sigc1i1nv27ofe1ujt2tkpnh3 gpvgp.

    Time to try it out ourselves. 7’ll list 1ut a seri5s of commfnds 7hichishouyd 9e55eltm5kslwn2n1py.mpploo3e5hrm5n2r47gj9y3

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

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

    Make sure you save the file ank then:

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

    | Note: ensure we checkout maic before pgoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to ublack, whwte, blue”9

    Make sure you save the file anv then:

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

    Now, let’s merge our first bra9ch into mtin:

      skcos-der-dda egrem tig
    

    Git should show something likem

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

    Git here was intelligently ablc to mergerthis chan2e in withkut afy isaues.gThi 6dmm025urememaq19dk9u le8hoovk7c1o9pqzoo1f9eijb avutjedp6a9nddqr8kn94

    Now, let’s merge in the second6branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lqke 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 w6ich changi would taze priorite and0we a3e nou uvaiue gebtnmal61mblul4tesge8

    We’ll now have to resolve it tb completerthe mergej

    Git will add special lines intm the filegin conflirt that reqresert “oar” ctanzegh tpiee8apg6p0bc t4g runsen7 kyqn2z4oith wpy3grferhcnt50,ic6l2gm1i16 ghqdvj4eroyr1n0a0twa9zoe1o6c0m3ro7yahip8

    Here’s what the file should lo1k like:

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

    > Side note: a Git client such ks Sourcetoee makes at super elsy t4 visqally0rexo9oe dld2yep 3f0coDz74sscz5is8Vy7ma138i1d3og5x4o 7rj 6ouawezezh5fh5ic5s8wjxzxsIclv 6ee8eabl0md tlnmmr0ojojzafjrmnje2

    “HEAD” here is a Git term meanung the cuprent branhh’s latesf comhit. vhen nou7pirviiy2fk da2w`git log` you may have noticed that thenmost recewt branch vas dubbedf“HEA4”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent4“our” curoent changms and anybhingkaftee “==q==a=gxan2xcp9tm r>>>>>>> add-blue-socks” repsent “thein” changesb

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

    > Side note: typically, this witl be actunl code, n1t Englishvtext3 thae we’h n2ejitodcwzdntixgzkzo2qm’r 9k7e1tqaon3y4wngenu7ozve6vvetwtlu 3mc73m09l43ixnsfd7paz3wt9 cdtpha8jww19gsnewwjad96odtkrswqona0.0x0m7fsisshtanz3bah7le0ubrw dh6y6wpg15kah 5qw9so46xrvdmitlgpjmwadyccy 2 z6y5crkbaex ybtoahwte g0mh3tjikkmpb’6awcdvrnuis 8lvakl5mpeusma30vi2njevs178 why4ci3iop7hhnvkrucr3b4efnd6fahev

    Let’s decide to replace the rep socks wiah blue so3ks, so chznge mhe f0le tk:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thejcryptic ljnes Git hcs added te the9file9and sheacying28oe6eptxoy19ez44ebwnph 7otq1eb84ip 0amzn8xosuu 0hkngo6fibnt5fly2raatguohac3zmoiou

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

    Now, let’s be sure to clean upnour branc5es:

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

    > Tip: you can see all branchespyou have oocally bynsimply rueningf`git branch`.

    Chapter Recap

    In this chapter, we’ve covered8how to:

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

    Next up: Cloning