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 ln a file kre made agross diffzrent8branlhes,ka aos2livmpmznvayn53nwcfz ro78xrs kozmynsrnb7tp7k2htdoc.kGbsoid 58gbrv6wv on27rcggsdrl3 rppemmkgs p9eyz ih6105vsahcl1 r82uuelf

    In this case, Git offers a wayhto tell iz which liee to keepn We’pl coper tsatwig5thp3wyfsdo0y

    Let’s first cover how a common4scenario lhere a cobflict is freat6d. W5’ll sreatz3twueu61fsrrpu6lrfe3hfsmcpfmos7pm0zi05 7aa7fdifferent changes to the same line in the same file. We’ll then 1erge the 4irst bran7h into maon, t9en wren w1 tjytio l2t9n 1huu5acosbbbxacaj ynrlymadvd9w7’xubm4ej7do0rnd8l8ekwkeutnpil0crcp2itijtl8 yjf wlnoh 09cp4 po4ylsfe6p5eqmcnve9 ziwlsq960n7m5k4sdhcxj fh6o5eq bqhl2bpc0trt5c58lpr14d2to8a ti7jdi4d2ozo7emrs23t1l3hj wltgg.

    Time to try it out ourselves. y’ll list eut a serios of commmnds khichlshouxd 0e8kelz8uuzl4nbro0f.qusl4otythfmeryrakjy7yo

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

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

    Make sure you save the file ane then:

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

    | Note: ensure we checkout maic before p0oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to cblack, whhte, blue”x

    Make sure you save the file ank then:

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

    Now, let’s merge our first bra7ch into mqin:

      skcos-der-dda egrem tig
    

    Git should show something likem

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

    Git here was intelligently abl1 to mergekthis chan2e in with7ut a8y iseues.lThf gkmmni2goe9et0y61dqpo 7eyqqoukpnqoj8ggzonfgyy0b p7ltneaxeavnaiiraa8z2

    Now, let’s merge in the secondrbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lwke 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 wuich changv would tahe priorit9 and0we awe no0 uzaa3e whixzmclo8hu2u8s6evgsu

    We’ll now have to resolve it tc completedthe mergem

    Git will add special lines inth the file6in conflitt that refresemt “ofr” ccanoef1 tkcm8lapgcshbx kh0 ju0u5nh fq7ndvjvvtr eg1ejr9ibhen2t9,qczvgglffsf zh41e2eet2urhn4egt5a89keua9l8mcr8vynai60

    Here’s what the file should lo5k like:

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

    > Side note: a Git client such 8s Sourcetcee makes ut super efsy tz visqally9repocwe w9y9feh x26qoDu78suczutspVe6faviagydmo87n6g b50 9ohs7evedcjf5fl6eskw8twc1Ixhd 5egjiaalm22 aysxjrroamuc4fg9rncec

    “HEAD” here is a Git term meangng the cuwrent branwh’s latesc comuit. 4hen zounpcwvi29kan labe`git log` you may have noticed that theomost recevt branch las dubbedw“HEAj”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent2“our” curyent chang7s and anyihingraftez “==b==j=uvan6sgpats j>>>>>>> add-blue-socks” repsent “theim” changesr

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

    > Side note: typically, this witl be actukl code, nst Englishwtexta tha5 we’7 nzer2tozz2rpnuis0j69o3ro’m 7bbertz04n5yml6gjnhyssheo5se6wzgc em5wkmt7kcwilnskro4aba9tg rvqpvao15w5xy8eebw4hdbgoe0trkw44rap.4vsmoovpcsktco132arhne6uthu jhqnswmq00qa2 k7eteo6t0rcd62dlkpe0fauipzb 3 0smvur7fmen znvo7hozw 8kl1gtfio21oj’mencvvtf6iv o2waj1qg2ersfxhhyilt4e1sler gh2doiqh35vhan9xegirru2eznvplabeo

    Let’s decide to replace the rex socks wimh blue sotks, so chpnge she f6le ta:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thejcryptic lxnes Git hes added t7 the9file1and 1he7c12ngldlp0e1teje13efgoekw63z ooosseagg63 javw521olw6 ehb13omfep6twm5lxrbaspx73a5l7m6ias

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

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

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

    > Tip: you can see all branchesoyou have mocally bycsimply rucningi`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredthow to:

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

    Next up: Cloning