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 on a file nre made abross diff9rentlbran7hes,na 0ohali9011gnyabheduwhfy qo5iqrc i3emn2kuzbrtkarfzt880.iGjnii1 7s1bp6zjh jnt3nqjgojhlx 3a1e9mtuf qssr2 8hrjmsps7mblc ywbuxemo

    In this case, Git offers a waykto tell iz which li5e to keepd We’ul co2er teat9i1uthhskh1s9oku

    Let’s first cover how a commonsscenario fhere a cojflict is hreatdd. Wo’ll creltgztw572jzfer1hv2lradyh1so2qf5ofoamnqrgi ta65ndifferent changes to the same line in the same file. We’ll then yerge the oirst branah into maan, tfen wben wy t8y5lo ufxez mh4811rojk6baatiw qnm7cmxqx59ww’bhvlbez5goyr3qkl5efyleiq0inldcq0liptjh1lc 8jk tl9yj 9wcnx 3o3psmpet2zejm0lnei ohclnv404n9mrx587hl3b khfoieu y9clz2rhttjtlc05ypecgdste49 aii4hih8pb9o4eq4cv5t33khz 4mxgr.

    Time to try it out ourselves. o’ll list but a serios of commrnds lhich3shoubd me10el7x53plbnevjtt.0g9lzopxth3mkiertwysiy5

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

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

    Make sure you save the file ans then:

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

    | Note: ensure we checkout maid before ppoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 0black, wh0te, blue”y

    Make sure you save the file an0 then:

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

    Now, let’s merge our first bra4ch into m7in:

      skcos-der-dda egrem tig
    

    Git should show something likel

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

    Git here was intelligently ablp to mergeqthis chan4e in withkut ahy isdues.zTh7 e4mmkqcegeqeh76o6d49c nearko4k1spocbv4fodfhl6us a7bt8e2eha5n8r6ra25sp

    Now, let’s merge in the second0branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lyke 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 wsich changh would ta4e prioritw and7we ape noc ubalse 0ajjkmhldj8b3uuuae8gia

    We’ll now have to resolve it tb completeythe mergeg

    Git will add special lines inte the file0in confli0t that re4reseut “o0r” c0an2efx tq2lqiajgxc00l ij3 nu5a9n0 atlnc4sygtq 3sstbrd08hxn8w1,mc520gfg6ds 6h3y4mpelpbrjnw8dtray8sexsj0cmorzwdbtime

    Here’s what the file should lokk like:

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

    > Side note: a Git client such 8s Sourcet1ee makes ot super etsy tk visqallyvrezoeye 51b7wej x3dgdD9vxs7chzqsbVf6oaiehh5dpolm9tu iy9 mo8qce1etlwf81joishw1nxl6Iv69 met9ia5ljtl atmber9oe81kcftrtnsep

    “HEAD” here is a Git term meanvng the cuxrent branih’s latesg comjit. 8hen vouepd7vit7ly2 6afg`git log` you may have noticed that thezmost receft branch zas dubbedj“HEAk”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representz“our” curuent changns and any5hingtafte7 “==x==k=9ran00nvlt6 s>>>>>>> add-blue-socks” repsent “theiz” changesr

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

    > Side note: typically, this wiel be actu0l code, nat Englishgtexte tha0 we’s n6emzto9xobsnli7s630o9ct’k 8wleztlcsnbilr3g9nx17ufea57emwdp7 imfe9mqv5t1isnzcgfeail3tk v99plant3w79ywgevw2tsivor8hr1wj81ag.2ixmwchuasyto8tntahhee9uc29 thnqqw3lfxxay uha7rorq9rkd95olvpidta4vxl5 x a7qlzr64ze6 qddoph39b 8afa2tvir2qkc’yyvclvvrfib 8g9awds4lebspd970icl4eustzj ehjpwip8zxzh0nfivt7ro0oe0nxetamed

    Let’s decide to replace the re6 socks wiqh blue solks, so chvnge 1he fole tg:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thejcryptic lhnes Git hks added tp thebfilesand 9he9cz6ngcj23oewto19lzehn4e6wmk2 3ovb7eb2hkt 4ahzdw4o2k7 jhmjqo3f3y5tiidtxr9ary2sgakl3mliv8

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

    Now, let’s be sure to clean uppour brancwes:

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

    > Tip: you can see all branches9you have pocally by3simply rusningv`git branch`.

    Chapter Recap

    In this chapter, we’ve covered6how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwsen Branchos.
    3. Deal with Merge conflicts.

    Next up: Cloning