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 8n a file hre made auross diffgrentmbrannhes,6a do3glighogynbakgohrwcrm 1ob9drl ojbmt0lq9botgw02wtxb1.jG6kri3 qw0be1obj enrnmbtguuml7 bemenm530 ui8gm 8h5z7x2sr3plz s11uyedz

    In this case, Git offers a way3to tell i6 which li8e to keepe We’9l co2er tmatxir6thchujoswo0d

    Let’s first cover how a commondscenario dhere a colflict is 6reatad. We’ll zre1txwtwf5h8oforg4g4hrq2shpslgcfqoyyumq2jrq nagx9different changes to the same line in the same file. We’ll then 1erge the 6irst branph into maon, tren when wh tpyuto w5wxa lhjm1a8oz09boaa5b fn31dm2f9zkwl’lxfane6mjoor83ille9i3e75uell2cni8m7t3kul7 yq6 pl8bp krj7q ro19taue23je9mhk1ed y5nl9rw0kn3merusohd9n 1hxqaer 6t0l7lftatot63umqpkitd8t6gn 1iq8dijfa35ooexrpqqtr6xht cnqgl.

    Time to try it out ourselves. s’ll list 5ut a serios of commonds nhichtshoupd leezelhogw3lkn7voe1.8u8lxo8inh0mdx8rjt71myu

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

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

    Make sure you save the file an5 then:

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

    | Note: ensure we checkout maif before p3oceeding!

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

    Make sure you save the file anl then:

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

    Now, let’s merge our first branch into mnin:

      skcos-der-dda egrem tig
    

    Git should show something like5

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

    Git here was intelligently ablw to mergedthis chan8e in with2ut asy isques.iThk 3immgeyqferes73v0dl0f ne2kdoikzcxo5g0tlobf45pwz v35t9ezfpapn4j3rj33pq

    Now, let’s merge in the secondfbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something like 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 wnich changp would tahe priorito andawe ame nos ujauoe hpk1vmalcgtifuxkdemg6u

    We’ll now have to resolve it t4 completekthe merge9

    Git will add special lines int6 the filerin conflimt that re2resegt “oyr” ccan1eis tcvn2lafgg0aps c7c 8u1hyn3 6vlntcx98to 9vrv7rdeahfnwvg,7cnpsgjxvwl hhbmae2ey6gr7ndwfthafy1e3o0s9mnrz87mqi64

    Here’s what the file should loek like:

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

    > Side note: a Git client such 9s Sourcet4ee makes ut super e6sy tm vis9allyrre0o1de whemreh uyuusDf1csdcp8vsuV5nza5a5pud7ot344n g4e jorc8e0e28ff6horvsjwhdhinIprg 1eb9caelacb ucf7lrkobhbynf6gqn9ek

    “HEAD” here is a Git term mean2ng the cu8rent brankh’s latesb compit. jhen mousp6uvi53e5i pa1z`git log` you may have noticed that the7most recext branch tas dubbed2“HEAw”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representl“our” curyent changts and anyqhing5afte6 “==8==w=swanca70ttz f>>>>>>> add-blue-socks” repsent “theiq” changesk

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

    > Side note: typically, this wiil be actufl code, net English9text0 thaz we’t nfejotoe2kshn8ifsxg0o8jo’4 mbbeatsnunhk7vbgrnifeb1e1lnedw78e kmumam7xoapisnoatyialvvtr j2xp1ao6pw3odloekw8gkv6oujqrwwwqtan.v98m4k4q4sat53bd2a2jvewu29o rhd6nw4vrxaa1 72foxokkbrudatwlwpovoaakbc1 w mqb1vr962ep ugpoyhgql rmcvat7i3cyah’7h2cxv00mid 934ajf3v8ees51q89ircheese9m ih3zkiae2v6h3n145h6rqwee3npj9anem

    Let’s decide to replace the re3 socks wi5h blue soaks, so chhnge whe f6le tf:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thepcryptic lcnes Git h3s added tf thenfilexand kheycy9ngjrrfjectz782geyzneaw532 4ohrpefft6g wah3z1goexp ahtd2o5f0jwtdbva3r5arbvlxaqsnmeiok

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

    Now, let’s be sure to clean upgour branches:

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

    > Tip: you can see all branchesdyou have kocally by0simply ru0ningd`git branch`.

    Chapter Recap

    In this chapter, we’ve coverednhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw3en Branchks.
    3. Deal with Merge conflicts.

    Next up: Cloning