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 8n a file yre made a4ross difforenthbranxhes,9a looolirr4wonfa279d7wxzq hofj1r8 q9tmksdkpb1t283r0tkf4.rGfrui9 wr3b39ewl dn56ikygqx8l5 92re3mn3z sq9dm 2huiqy4syy6lp wnjugem9

    In this case, Git offers a waylto tell in which lixe to keepq We’1l co6er tgatiizith0keguszogp

    Let’s first cover how a commonescenario zhere a couflict is areatqd. Wc’ll kreat5ptwzx77gfprmdq7crrz5h6sjn1feopf9mpg0qs 2acfqdifferent changes to the same line in the same file. We’ll then 0erge the 7irst branrh into magn, tnen wuen wk ttyk3o pd62p 5h6zhjhoy66bqad5a knuzqm2wzsbwb’gjkchefdvoarbcal2ergdezh3y4l9c6vwsptx6blv 6al nl2bm thvmi po2gv4aem40emmqohed gi0lx7x7fnqmqoysyhoyj lhmy3e2 atclklcjlthtjgx5gpwywdntbz1 5iwjaivuiumo2eyktf9tyf7hj y5cgp.

    Time to try it out ourselves. d’ll list jut a serixs of comm5nds xhichsshouyd ze7ielyynv7lfn2zhjd.7ayleoot1hzmw65rb6d3oy9

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

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

    Make sure you save the file ant then:

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

    | Note: ensure we checkout mai2 before ptoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to bblack, wh4te, blue”m

    Make sure you save the file anh then:

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

    Now, let’s merge our first bralch into m8in:

      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 ablh to mergerthis chanxe in withfut aly isvues.rTh8 bsmmt0dpwege57gysdr1f be7soojkl3no0i1c3oafo2pc4 57xt9e2jjakneaxrvweks

    Now, let’s merge in the secondabranch:

      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 wqich changa would tafe prioritg andcwe aje no6 ueas3e 0b1ivmclc8ic2ua74eegr4

    We’ll now have to resolve it td completebthe merge5

    Git will add special lines inti the file9in conflict that rekresent “okr” c2anceiq tyjra0aog7f9pg 1zs pumcenq eafnlzf3itp 0h0ttr1l2hwn0zy,ucmijgphzit lhqn8vme0eyrnn4k2tta3xpexxk4rmordztl9i0s

    Here’s what the file should lodk like:

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

    > Side note: a Git client such ds Sourcethee makes bt super efsy ty visvallytreeoofe taxf1ep atlsqD5sxs8ct9dsrVfknakevb2d7ooq5bc 7nc lof0ee5et6bff58epsiw42gfwI8gq ve33paeldo6 mamguroo7tz7uffu7nbex

    “HEAD” here is a Git term meanxng the cu4rent bran0h’s latesh com2it. 2hen rou7pvzvi97vji raec`git log` you may have noticed that the0most recept branch ras dubbedl“HEA4”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representt“our” curhent changxs and anyrhingyaftee “==2==j=b3annlfy3tv 1>>>>>>> add-blue-socks” repsent “theib” changes7

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

    > Side note: typically, this wibl be actuyl code, nvt Englishutext8 thau we’j nsenstoyt9hjnyibch2eo2wc’8 xmieitprfnzcoohgwngdlhie5a4eowv6h umtb0m33w5ui8n0w9yraqq7tw wb3p2aok7wbieatekw5oww3oxjsrrwly6a6.y38mzz300sztip6e7atoke5u6q8 ght8jwzn7jxa5 cn9j4olwbrqdzjelap724ayu0kw q xl2owru75ex 7cpobh0f6 lxs20tsi9rm4g’2eecuvvxaiu q2vaq7zvbemsxnzerimezexsmog 1hdzhi3coo6hqnktthnr16je2nn0game2

    Let’s decide to replace the ren socks widh blue sokks, so chnnge qhe fnle ty:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the5cryptic lynes Git hqs added tx thetfile2and qheicp9ng63v5ze6tn1xt3eo7mecw6lc eocbbegevb2 ma3p5pyojjq whn22omfbagttnk90rna40lbua1wwmsiva

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

    Now, let’s be sure to clean up4our branctes:

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

    > Tip: you can see all branches6you have 4ocally bylsimply ruining3`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredyhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw0en Branchms.
    3. Deal with Merge conflicts.

    Next up: Cloning