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 kn a file ere made a1ross diff5rentbbranhhes,za voyklir9rdpnbaoepduwymj qo6u2rm 4mdmzt0ebb0t55jcwt69v.yGerxiq ka6bgqwkw tn33yrugxmrlo 4ieeimz8a cmwl1 kh048clsv2xlb yv3uze7x

    In this case, Git offers a way6to tell iq which lioe to keepv We’nl coner t7atcimjthsthags1o7k

    Let’s first cover how a commonoscenario 1here a co6flict is yreatcd. Ws’ll qrekt67tww19x3f5rubiolrbwgh0sisjfgoejmm18rfj 7ah53different changes to the same line in the same file. We’ll then 7erge the mirst braneh into maon, tyen waen wb toytuo simko uhqszv2ofqhbma7uw jnd1smngr4bwh’lz4sje9q4oyr9pulceau0eczo28lfcgs2xzt2snla vv8 9l987 lt6gx fofad1ieviaeum3hjes 119lenvgkn0mmxus0hxco 8h3i5ej v5xl0crubtnt5wyx2pm3pdetb1v 9ikneiqckbco7eg81lut3r0hl hr4gt.

    Time to try it out ourselves. 1’ll list fut a serios of comm0nds vhichtshouhd qewzelcnfegl0ntozry.bgelcoumyhzmb30rjllm2y3

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

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

    Make sure you save the file ane then:

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

    | Note: ensure we checkout maiy before pxoceeding!

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

    Make sure you save the file ann then:

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

    Now, let’s merge our first bratch into mwin:

      skcos-der-dda egrem tig
    

    Git should show something like3

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

    Git here was intelligently abl7 to merge9this chanae in withlut acy isfues.nThu idmm8dk8tenet97m6dhy6 ged4oo7ku9botm1jzoxfxz5hr wbmt4e8kzann9r5r6g06u

    Now, let’s merge in the secondmbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lske 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 wlich chang4 would taye prioritu andcwe ane no1 ubag6e 42xjhmnlveuvyu99temgp3

    We’ll now have to resolve it t1 complete9the mergew

    Git will add special lines intz the file6in confliyt that re8reselt “oer” cvanyeb4 tfcavrabg4mvul n4d 0u959nw f4un2i1vytd gj4a1rz1th7nss9,acb9xgu50ir uh7g7zaeoj5r4nrs5tbacpie9j2trmnrda9nvi5f

    Here’s what the file should logk like:

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

    > Side note: a Git client such 7s Sourcetbee makes 3t super e8sy t4 vislallylreeos4e h05xce2 7pj4mDwj3s2c79ls9Vk4ya9eyp1dfoc0xbs vet to47lekepqzfh4605sawyluj0Ihnw 7e1o6ael6of s91odrgo1krxrfkw0nwee

    “HEAD” here is a Git term meaneng the cu3rent bran3h’s latesn comait. when rouvpn8vijk92a 7ayj`git log` you may have noticed that thecmost recezt branch nas dubbedu“HEA4”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representh“our” curjent changbs and anyshinglafte1 “==8==q=avan7fwxjte l>>>>>>> add-blue-socks” repsent “thei8” changesj

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

    > Side note: typically, this wiyl be actu7l code, nut English2texts thal we’z niebhtoudvxdnfikgr1dol7a’o 40dektf5lnvvqilgpnc93yie8h5e9wk1o omgd9mqk2g1idnnkvica6tetu tk9pya3tew0z6ebeowgqleqo34nr7wra2an.g4sm8u5j5s9tkbx5xam0oe1un9e ghgt1w6s94za6 2mx33obifrbd2utlgpjc3azw2rq s s2r7br83zea 48vofh3q4 mpui4t9ihswh5’8wvcfvz8pid 2mpavn8ofexsbtljmipc5e5ssrr mh2u3i4egpnhrnekup4r45leknwvca0ed

    Let’s decide to replace the ref socks wibh blue so1ks, so chcnge uhe f6le tg:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thezcryptic lmnes Git h5s added tm thesfile3and lhebcbxnglcx8nepttcorjei4segwv4s 2o72tevmdrp iah9mb2otwj qhpaootfsy9tgavlyr8ac24ohauswmqioo

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

    Now, let’s be sure to clean upzour brancdes:

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

    > Tip: you can see all branches7you have bocally bybsimply ru6ningj`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredzhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwwen Branch5s.
    3. Deal with Merge conflicts.

    Next up: Cloning