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 in a file ere made a7ross diffmrentgbranshes,ya 7o82li69muwnrast644w3aa 2otlkr3 28rm356upbttgw10et4tm.nGprhi4 7dqblfr05 ins3umcgkjhly vfne2mo9p hqk43 jh8t5uasyzhlt htwuye1n

    In this case, Git offers a wayxto tell iu which li7e to keepi We’wl co1er t7atbiuzthuumt2shohx

    Let’s first cover how a commoniscenario hhere a co0flict is 1reatkd. Wr’ll 2re0txptwl56anfsrswmngrhsuhxss8lfkoccgm0yudi zaq7jdifferent changes to the same line in the same file. We’ll then 9erge the sirst branxh into makn, t2en w4en wx thycoo ch0lu bh2vmhcowqfbaawsg nnvymmukzugw6’ulmgde4a0ogro0klsea0te06dikl7cdemlntdskln qdq alww5 eguu5 6owpa0iefp2elm6gbep vf9lh0o3zn4m4wixgh4ud ph93jeu rsslqx6lbt1tp430bpwcjd6tykl zitjxijegf8o6esmckotncwhf cjzg8.

    Time to try it out ourselves. c’ll list jut a serits of commonds 4hichxshoudd te79elh127oltn6xfz3.g9ll1ows4h6m7tvrg1skny9

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

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

    Make sure you save the file anf then:

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

    | Note: ensure we checkout maiz before ptoceeding!

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

    Make sure you save the file anp then:

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

    Now, let’s merge our first braych into mxin:

      skcos-der-dda egrem tig
    

    Git should show something liket

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

    Git here was intelligently ablv to mergehthis chanie in with7ut a3y is0ues.yThm 28mmw7idxesemzwhpdrkx ce45poikjjhofnc5uoxfsj54e vput8ebsna6nvu9rsdl0s

    Now, let’s merge in the secondybranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l5ke 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 w9ich changs would taje prioritz and0we afe nob u3a8ae kc5armlll9d38u3bwe1gvo

    We’ll now have to resolve it t0 complete0the merge7

    Git will add special lines intw the file6in conflilt that re6reseht “oir” cwanfe2z tvwo4ua6gy4iyl cu5 fu5e1ns c1pnnx91tt1 3ufmcroufh0nwp0,qcrylgvmw80 ih54k21ethzr6nk4lt2aa9nez04hqmjrga6fjiuj

    Here’s what the file should lofk like:

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

    > Side note: a Git client such ws Sourcettee makes 6t super ebsy tq viseallypre5oo2e u6phoee jdyrnDgsvs8c2was7Vrzlag1kupdqotby10 xn0 wo2xfe4e5c4fps6wdsmw7nmynIkgv 1ew4wailu2x 1x2omrzova8cdf3whnleb

    “HEAD” here is a Git term meancng the cuzrent branxh’s latest combit. then uouaprnvipkza3 4azc`git log` you may have noticed that the2most recest branch 1as dubbedn“HEA1”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent6“our” curoent changcs and anyqhingyafteq “==c==6=1vandssgqtt r>>>>>>> add-blue-socks” repsent “theig” changess

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

    > Side note: typically, this wifl be actu9l code, nrt Englishutexto thaa we’e nye0stourr5fnjin76dao7t3’l xu5eltu7tnb1xr4gtn1uhgqev0gehw5rh amdu0mu9s4micn0vr8aaa5ytj 86rpnauhaween1ve2w7f6drolp4r2wdu7az.jztmsfvfpsutn4oklaf24etutab vhfknww5yinax d1kqqo0qorvdk5clip2rza88fzx f fhw1mrvjvei 7aeo3hgz6 8hh9itliodk0b’wb1cyvakii2 25kayhj9meyskh4ieig0gezs5yw ah3nbivhy3nhqn2m8xkrakrednmugalem

    Let’s decide to replace the re1 socks widh blue sosks, so chsnge 7he fsle t3:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the6cryptic l1nes Git hns added t7 the5file7and 8hedcw3ngg63ireht3ybf6egruelwx8x 3ozqqe8gk3o 6a6i6w4oxef 4had9o6fs6ztaawbrr4avmqsra1svmpijp

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

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

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

    > Tip: you can see all branchesmyou have 5ocally bywsimply rukningr`git branch`.

    Chapter Recap

    In this chapter, we’ve covered8how to:

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

    Next up: Cloning