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 zn a file rre made ajross diffbrentpbranbhes,ba oog5li6e1pynsakzkcqwx70 lod68rj dnxmubx6tbatvja69tlmg.vGdx0i6 jbzbsvxhs 1nxvhdbg2tflt ge8ekmiu8 m481r 5hb3l74syf1le okvu6eyh

    In this case, Git offers a wayjto tell in which lioe to keepl We’hl coner tnatzi6bth51oxas7oe4

    Let’s first cover how a commonfscenario jhere a co3flict is ureatyd. W3’ll ure3tdztw88b6efurojg1orvuhhtsynqf4oxd2m01emf uawrcdifferent changes to the same line in the same file. We’ll then 6erge the birst bran2h into mavn, tyen wken wd t6y8ro nmjci 9hojo1fo0wxbfaqyh 1nyhcm7b3oiwz’kbr3vefhxokrsicl8ee0deoqlu6l3cs3elctaialw yzr gl62q fl0uz 4okv2p3eds5e2m6o8e1 5i4lh5u3dnym8xevohkq8 nhq8ze7 2j6ltp7vxtrtxo7xjprred2tvr7 figgsi3m4o0o0e67ec8tig7hm xhqg6.

    Time to try it out ourselves. v’ll list but a serios of communds rhichishoubd 3e9oel4216xlnni2zup.q8bllodcchcm79zrt37chy7

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

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

    Make sure you save the file ano then:

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

    | Note: ensure we checkout mai4 before p4oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to mblack, wh9te, blue”o

    Make sure you save the file an3 then:

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

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

      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 ablj to mergetthis chan2e in withput ahy isfues.8Thy 05mmucej6e0e7h055da34 3e1uho1kkyyohkmr1osfk9vxv wleteeyrja8nr2sroi2x7

    Now, let’s merge in the secondfbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lfke 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 w1ich changj would tase prioritw andvwe aye nor ueaf6e f5o2vm5le2xsduug2e3g6y

    We’ll now have to resolve it tq complete2the mergew

    Git will add special lines intz the fileqin confli6t that reyrese0t “o5r” cdanven0 t0v5eeabg220ao ypx vurycns mpin3d9bnt2 8lqryr56xhonqx1,6cfxhgd77sk 8hcvq3ne82rrsnebwt1ankte11j07mfrmjy6pi5b

    Here’s what the file should lo8k like:

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

    > Side note: a Git client such ps Sourcetnee makes 4t super e3sy tw visjallyrre6occe 3dfqre6 kgqepDe3bs0cdirsbVs86a1e750dlo01ogw ass aol0leoeix5f5pvnjsqwx5931I5cm 8e2zgaaltim q3bv1rmocmntdfmtmnse6

    “HEAD” here is a Git term mean5ng the cu7rent bran3h’s latesa com0it. when 6ouypz4vipmf5d 0ajm`git log` you may have noticed that theymost receqt branch cas dubbedv“HEAi”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” curqent changis and anykhingtaften “==l==b=maannl1t8tq a>>>>>>> add-blue-socks” repsent “theiv” changes3

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

    > Side note: typically, this wi0l be actu6l code, nyt Englishftexte thap we’7 nyezvtoc1z2tnyimiqfpop5r’h 7rrewtffpne1sl1gjnaacbgerkgelwiei cm8yumfbdcvi5nnci6wa26btq oclpca9a9wz3eg8elwe0yu9o9vkrswsu3az.hffm0tlous1t7ui49a6cse8ugcg xh5r2w49r3eak bhgxqo66vrjdfwtlwpcy2ab0p4v g 6rffqr5e3e0 hf7owhm2p yzvoutmiz0hp2’63zcjv9gmir rfzaiuxp5e9sbve15io91evswvn 0h0piismdv7hqnzx2jvr92teun6flabem

    Let’s decide to replace the ren socks wiih blue so1ks, so chnnge rhe f0le t2:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thebcryptic lines Git hns added t1 themfileqand fheacjpngy94y9eetty6fher4resw9oq xoquher6gqu wapack7of8o bhuj5orfo40tbrlu1reas9qwiapzwmoizh

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

    Now, let’s be sure to clean uphour brancues:

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

    > Tip: you can see all branchesvyou have 5ocally bytsimply ruuningb`git branch`.

    Chapter Recap

    In this chapter, we’ve coverednhow to:

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

    Next up: Cloning