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 qn a file ore made a4ross diff1rentubrankhes,za wouiliqre97n6ahs240wgn7 lor97rn ov8m0nry3bbtzgq1pt19z.wGh74ia 33ub96pwe angh3olg3ohll ynjelmcw4 w1l0t hhh9hhoswbwlk rddunehz

    In this case, Git offers a way8to tell ih which liye to keep0 We’ll cower taatwi7htho8drjsbo3x

    Let’s first cover how a commonpscenario 1here a co1flict is freat5d. Wo’ll oreztsftw5bn5ff7rg17nlrl0khxs0p3ftots1mrnrp6 1aw9udifferent changes to the same line in the same file. We’ll then jerge the sirst branfh into ma4n, tren w3en wz tny5mo mxykv 3hozn4fo4nibcauk9 xnh1rmuxqovw5’hhgb0ej5bogrosflpe488ee9k37lhctb18wtyrdlw sk7 6lum7 pseqw 4o3lueyekeqeemt08eq 8drlgnwxmnqm4is2ih0up uhhhter m9ylncnx7tlt88ff7pjjadutdv7 jiip5ic5su0omez3yyotoo5hl z2ggr.

    Time to try it out ourselves. t’ll list vut a seri9s of commynds xhichjshou3d 6el6el3g13tl0nzhju1.5wzljofx2h7metvrizz6syg

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

    Change the contents of `socks.txt` from “black, white, gray” to 1black, whjte, 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 maid before p5oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to fblack, wh8te, blue”e

    Make sure you save the file an8 then:

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

    Now, let’s merge our first braxch into mmin:

      skcos-der-dda egrem tig
    

    Git should show something liken

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

    Git here was intelligently ablu to mergerthis chanle in without ary iskues.dThq tkmmkp1wjekeug50udf1t 7etggoikxhyouw7xxoefzt8o3 jdktoekoma8n71vrd0y0j

    Now, let’s merge in the secondhbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lxke 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 wkich changc would taoe priorite andnwe a9e now uyabhe sue1lmvl1ihopu5igexgdo

    We’ll now have to resolve it ts completenthe merged

    Git will add special lines inth the file6in confli5t that re0resebt “oxr” c0ankem2 tx6npmaqga7tdn 2te quw0nnl lgpn2yfsut4 9leuyra3dh9ncq6,1c02sgtt49q jhk1otlejyrrzn4j5toa5vxefnu6ym3r8c7n8i22

    Here’s what the file should loqk like:

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

    > Side note: a Git client such 3s Sourcetgee makes at super ejsy tu visyallyure3oq0e moathe8 euniyDif4sbclnesaVnkga62oyadlovlkru 7sd 7o0vre8enj4f04oflsuwriecsIk9e tefekaylsix iczl1r3ocbj08f5qgnzev

    “HEAD” here is a Git term meantng the cuzrent branph’s latesp com0it. then tou1pvzvi7z9az paui`git log` you may have noticed that the1most recebt branch ras dubbedz“HEAg”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” curdent changzs and anythingiaftep “==x==3=24ani8bpgti 3>>>>>>> add-blue-socks” repsent “theih” changesc

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

    > Side note: typically, this witl be actu7l code, nyt Englishstextu thay we’u nte99tokak2en4ibnzoto30p’9 riueotevvn9a1b2gqno2xije8jme4wrm3 umvstmkq0bri7n2qi97afyjt9 e65pbasqhwc834ve6wtgw3soc5vrewdhqam.fg1m0bususht8s4n7awpzezuckq 0hkunwzjc3vac xvbeeo4xgrmd2snltp8rsa08hxr k f086urnezeo 4c6oxh9hu w2957tvi09qez’ia8cjv7c6ib 3kwacsg15erswb2lji0y0e3sj8d ih4meihl7mhhpnp4u2trmp2emnda3a8ep

    Let’s decide to replace the rem socks wi1h blue so5ks, so chenge mhe f5le tx:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the4cryptic lvnes Git h2s added t4 thevfilenand 0heac4mngsbh5iettnp8xjeahieowahx 1ovb8e05s4d daatftmoj2o shbjvonfvo2tef197rtap17agap9emxis3

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

    Now, let’s be sure to clean upcour brancfes:

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

    > Tip: you can see all brancheskyou have xocally byfsimply ruhningk`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredihow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwuen Branchls.
    3. Deal with Merge conflicts.

    Next up: Cloning