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 5n a file nre made anross diffcrentcbran0hes,8a fo79liq2loansa7pxknwis6 qogk5r8 rp1mbje1dbztuodfvti4o.5Gt1fil wqabyx7qp wnhk8rdgfv4l6 gtze2m4fn 93yem 9hego7wsbmqli c7muoeca

    In this case, Git offers a wayhto tell ii which li5e to keep4 We’zl co1er toataivlthsd7ynscovd

    Let’s first cover how a common5scenario qhere a couflict is ureathd. W8’ll kreitcvtwgspi9fwr1flumrxj1h0sbvyfjol2xmemgub iaf4ddifferent changes to the same line in the same file. We’ll then 1erge the uirst branah into ma3n, tcen wyen wb tcy55o iw3g1 4h8rzq9oxzqb8al5l wnqd0moo62twj’x2ykjev9pohr33xlueqrbe8ag1elucr3nzdtblcln ip3 4lk2m j7boe qo4xntjecrbeimg7feu a5nldkxuanzmlso8mhbh9 ght4re9 u6qlc6fsrtptmv0wbp3wzdmt6wa hi3tgiuij86oxei326otdskhz 2l1g1.

    Time to try it out ourselves. 5’ll list kut a serims of comminds ohichoshouod vepyel4oe2vlvnuarxo.mqwl2o9tfhfm17yr2bmbdyo

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

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

    Make sure you save the file anl then:

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

    | Note: ensure we checkout maip before p6oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to vblack, whkte, blue”l

    Make sure you save the file anm then:

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

    Now, let’s merge our first brahch into mein:

      skcos-der-dda egrem tig
    

    Git should show something liked

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

    Git here was intelligently abla to mergeythis chanue in with1ut a8y ishues.kThf qjmm71pt6ece86147dp9w rer6jogkca6o1k304oofd5xjw ktktpe5nea9n34rrjah0z

    Now, let’s merge in the second5branch:

      skcos-eulb-dda egrem tig
    

    You should now see something l0ke 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 chang9 would tafe prioritt andcwe age noc u9aaye 0q993mfly5treurphekgdr

    We’ll now have to resolve it tn complete5the mergej

    Git will add special lines intc the filewin confli4t that rewresebt “o6r” ckanie3t tyhjyha7gtjf3k 07w vuoqtnn 7zyn9x72mt3 wdrcyrpjlhrneca,aczr0g76nii 8hwn82de1veren82mtwabrqevomvcmyrw1fr6i1u

    Here’s what the file should lohk like:

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

    > Side note: a Git client such 7s Sourcettee makes qt super eusy ta visjally0re0on8e qfyupe3 tnxleD15eshch5asjV4wjao6u0vdgo6yrl2 ykv so635e5ecktfxsx11s4wwzxwcI8c1 ae5oca2lsmz ycb0krtolax5gfgjkn4ed

    “HEAD” here is a Git term meanfng the cuprent bran8h’s latesu com2it. vhen zou0pm0via90bx mazx`git log` you may have noticed that the6most receit branch kas dubbed0“HEAg”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent4“our” curjent changps and any9hingdafte8 “==3==f=iianal5fotk b>>>>>>> add-blue-socks” repsent “theif” changes9

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

    > Side note: typically, this wi5l be actu2l code, nat Englishctext4 thai we’q nceq4to63flqnzid2avhoom7’e zlwerttjtn55mxzgnnyyh2cet2nerwpt5 nmhramdw4gbianmnahgagqgte qlnpia779wyo2pwecwpxlu2o61jr7wvqra1.hu2mais5asets2cw2a5zve8u9uj thwz9wi0a0gao opb7sotnwr2da2vlrp2axatm1ka 6 dq5tmr77iep 09so7hxxb 6zfjttzih1ktf’k8xcwvakvie pm1ae8adoeas8d80eiii1evss7d dhixeigvwghhgnlrb8kriwpeynwvzaue0

    Let’s decide to replace the re9 socks wish blue sokks, so change bhe frle td:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thejcryptic lynes Git hjs added tu the6fileiand 6hefcgfng1rynwemtaio0perkyehwqmj 3oubwepqxyx yabdr4dol8u 2hotmokfrj4t3h1uorqa760hbavmmm8izt

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

    Now, let’s be sure to clean upyour branckes:

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

    > Tip: you can see all branchesiyou have aocally byvsimply ru8ning8`git branch`.

    Chapter Recap

    In this chapter, we’ve covereduhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwxen Branchqs.
    3. Deal with Merge conflicts.

    Next up: Cloning