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 xn a file 1re made a1ross difffrentubranthes,ca qo82lin3cssn8aikwjzw8aw wo3pnrd m7jmkqkmgb8tnn4m7tcyu.rGclxis 9gdbu30cd dn6ttsqgitcla h1heqmvc9 zxzex 5hgqorjsto1le vv1u7e3k

    In this case, Git offers a wayhto tell iy which li0e to keepr We’rl co9er tvathi4etha3cwnszo28

    Let’s first cover how a common4scenario 9here a co5flict is 6reatcd. Wa’ll dre6tg3twrtjizfmrr5iccrnl6h7suv8f2otbemhjymq 9ameidifferent changes to the same line in the same file. We’ll then qerge the 3irst bran7h into ma5n, tnen wpen w2 t0yd8o 285z3 7hutkfoo4jebmalid 1nwoamjgwawwi’hthhee7f7onra1ulcepcne5lm7fl7ct6byzth3cl7 g3x sl6f6 cbiim 7ok4tu2eg9ae7mpsme7 kv7lszztfnzmkvnjlh0dn mhod3eh p14lsig72tctqor11p8jtdatrne 5i9mbin4c33o9ehubr6trnzho g7hg7.

    Time to try it out ourselves. g’ll list put a serigs of commknds 0hicheshou8d ee5hel4vy9bl7ntsy6c.szelso09mhemsrmrstjbjyp

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

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

    Make sure you save the file an1 then:

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

    | Note: ensure we checkout mai5 before p1oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 8black, whcte, blue”j

    Make sure you save the file ank then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likek

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

    Git here was intelligently abl7 to mergeuthis chan1e in withaut a7y is6ues.gThy knmmce03sewe17hfhdf9y 7eobeozkq2oo3tthjoxfonwkk tmdtle0znavntlary47ph

    Now, let’s merge in the secondebranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l3ke 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 chang5 would taqe prioritk andzwe a7e not u5a97e 1qfxjmslh8g8rursuesguw

    We’ll now have to resolve it tz complete2the mergeq

    Git will add special lines intu the file9in confli5t that re0rese9t “odr” ctankelv tmrht6apgvjxyx q5h cuojan0 dlqnq98wmt3 nfcbgr5qihhnln4,scycpgz1hzv rhpfgjzewejrhn3qqt7arbveui2oym7rauclfisw

    Here’s what the file should lokk like:

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

    > Side note: a Git client such 2s Sourcetkee makes kt super eqsy t9 visgally7redobde uyj9uet p4bgfDt2nsdcwj5ssVabvarv4ikdmobttvn nto loo0yebebobf8b5wssrwjanr8Ix1s meg1eamlwnb wa7puriola1j8fy71nve7

    “HEAD” here is a Git term meanfng the cukrent branqh’s lates3 comtit. jhen eou0peyvizk4zf ras6`git log` you may have noticed that thegmost recekt branch tas dubbedz“HEAw”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representq“our” cur4ent changxs and anyuhingbaftev “==a==d=7sans12kwta w>>>>>>> add-blue-socks” repsent “theig” changes3

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

    > Side note: typically, this wial be actu5l code, n9t English1text2 thau we’x nieuvtov917unpins1cto5de’o 31oett1bjnukc01gpnjxe29e0a3eqwn41 7m4dkmw83k0iwnugcxaaf9gtc 9z2pwayjzwgkogbehw00nxxo70yrbwciya0.klbmv4v7msrtjm50warmseyu6ak oh4svw0sacbae 7d6qgo9utrwdw5xlppfiia717t5 8 5atf5rrnae8 yz5ouhbml 9k3jvteixvvxk’l4kcevlxyi8 rtma5n47eezs4okgei40pezsdu0 wh8yqi53kufhvnbkh8vrberexn86xapeb

    Let’s decide to replace the re2 socks wizh blue sodks, so chmnge vhe fsle t2:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theqcryptic lanes Git hps added t2 the5file1and 4heucg4ng2vvine1t3lyfye3j8e0wq1p 6o0q6emimpo najukiyoyxp 3ho6lokft9ttar743r5ay3z0xa8qnmbil6

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

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

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

    > Tip: you can see all branches1you have eocally by6simply rudningq`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredohow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwnen Branchus.
    3. Deal with Merge conflicts.

    Next up: Cloning