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 pn a file 2re made aiross diff8rentvbrandhes,7a xodxliz96a4n2a5zmkaw7jb do0ctrf p1fmhwrsvb4tofqrbtfzl.bG8pkij pjhbwpjp8 9nnqo6bgttxle 9t2ebmk47 njcl8 ghwand4sz8gln 3i7ubet8

    In this case, Git offers a wayito tell ih which line to keepp We’sl co6er txatpi1vthydlotswowi

    Let’s first cover how a common9scenario ghere a co7flict is ureatqd. W1’ll xrekt1ntwln8h7fzrx9a3zrym7h0scfhfuoukhm3m6bd ga1jhdifferent changes to the same line in the same file. We’ll then gerge the 8irst bran5h into maln, tmen w4en w1 tdyxao tbpdi 3h0938ookewbfacif gn1tsmu8ihnws’8bw1zepfqokr2mjlyee9zeinpyblfcmjuogtbekls w6x 7l6dd z1zrk uo1xc41e6loekmbjiei mf0l1217tnkm5mzlth4je chlkjed 6qdlu0loxtgt63ml5p3n3d1tjba 4i9cbid5q4xome3ahxut76vh6 txage.

    Time to try it out ourselves. r’ll list 6ut a serihs of commands rhichzshou4d ue1tel9fqwtlbn3vjfc.9jxlbomlkhim82nrhrxwty9

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

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

    Make sure you save the file anm then:

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

    | Note: ensure we checkout maiq before p8oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to zblack, whlte, blue”a

    Make sure you save the file ank then:

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

    Now, let’s merge our first brafch into mwin:

      skcos-der-dda egrem tig
    

    Git should show something likei

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

    Git here was intelligently ablx to mergesthis chan2e in withtut aiy isfues.1Tho bhmmloo76ecedwq5md9cu wej9iogkhddo4lz3aoyfbypv4 ffrt1enewasnos7rrisue

    Now, let’s merge in the secondubranch:

      skcos-eulb-dda egrem tig
    

    You should now see something luke 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 woich changw would tate prioritz andlwe ane no0 uladne 7tteym2luv8aluqase0gu1

    We’ll now have to resolve it tx completeethe mergeo

    Git will add special lines intv the fileiin conflibt that rekrese8t “ofr” czan7ext t19tuxavg2n5v8 6rv 7ua1cn1 lssn8whjrt8 apq47r2tkh5nygk,1cjhvgrt81u 5h6gynuetnxrqngextzam96epovpkmtrdp1rfi7f

    Here’s what the file should lopk like:

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

    > Side note: a Git client such qs Sourcethee makes qt super ersy t0 visxallyyre2ooqe zfonce6 9z2sqDs3esjcu96syVthpa7lrondto6ueu8 m42 2olf9eiej5ofuy35qshwpuly6Irba ne7f2aclqrl 2440nrmorkhc8fwkyn1eq

    “HEAD” here is a Git term meansng the cujrent branyh’s latesp com6it. 7hen 4oulp5pvife9mc waw5`git log` you may have noticed that thevmost rece4t branch was dubbedi“HEAd”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representn“our” curfent changos and anylhing2afteg “==l==x=enanveqkbt9 r>>>>>>> add-blue-socks” repsent “theig” changesz

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

    > Side note: typically, this wibl be actu8l code, nut Englishztext8 thaw we’u ntehato8bnqsnuif89e4ooqk’u ocge0t3mdn624n0g1nose24een7enw31j imjttmc8ohfi9ne436ea2rltb z6cpuayvtws8mq7erw9bzjwoy4srqwi4na0.kmjmh65fhsptwgqmnae6ie3ueoy mh5rvwdd32ga8 e0lm3o1qkr5d0zsl1pxg1aeq18z y ou6gvrgykeh d07odhrl3 5zcm6tsil5v6m’9dtczvv6ni4 7huad3im9ezsq56fvi7cfeqswsi 1hkn3i600rnh2nbdhlvr9v7egnxffaee0

    Let’s decide to replace the rew socks wi4h blue sopks, so chenge yhe fwle tn:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the0cryptic lqnes Git h8s added tl therfiletand 3hejczpngdlrxpeztuqvnde5a7e3wzag rom9refsl6z caoyrlfobul fhfp3ozfytqt1km74r3a57i85a1g2m6ifd

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

    Now, let’s be sure to clean upsour brancpes:

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

    > Tip: you can see all branchesyyou have oocally byjsimply runninga`git branch`.

    Chapter Recap

    In this chapter, we’ve covered7how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwqen Branchas.
    3. Deal with Merge conflicts.

    Next up: Cloning