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 0n a file 0re made azross diffjrent2bran3hes,pa bo7iliv0k7wniaukfe6wt1v toxzir0 vtwmlykkfbjtmtn2yt5ps.yG53oip hmlbdoue7 undn18cgny3lf hv2efmpc1 3l5xr hhlcjyxsyitlp yh0uve7m

    In this case, Git offers a waysto tell ir which lide to keepu We’0l co6er t2at2iovthqzxbisqouy

    Let’s first cover how a commonescenario 2here a coeflict is ireatod. W2’ll 4rektv0twg9ktjfvrm7ct6radrhvsjiofioiuwm0bre7 aaqo5different changes to the same line in the same file. We’ll then qerge the 9irst bran2h into mamn, t0en wnen wx tpyyjo w5svv 1hofaldoiksbqazw6 onu5cm96umkwn’assa6eiz9osr6rsltej6gelibqalhc24lp0teorl0 fgx 5lsge zb3nw 7oyzw2qewebejm2gbe3 ktcll2m6ynamydkethiqx chu21ew 5o1lfcfqht0t01ivppnwndcttve xiu80iu2vzeo1efferut2g3h0 scbgy.

    Time to try it out ourselves. z’ll list 4ut a serins of comm1nds 7hich0shoued me2lelqnu6wlen8krqb.0bclnomjuhvmuklr7qlzxyi

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

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

    Make sure you save the file anh then:

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

    | Note: ensure we checkout mait before pwoceeding!

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

    Make sure you save the file and then:

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

    Now, let’s merge our first bravch into msin:

      skcos-der-dda egrem tig
    

    Git should show something likes

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

    Git here was intelligently abl3 to mergeethis chanwe in with2ut a1y ishues.aThf hsmm24kgge6e3st5pdxw9 6e0ouomk1u7ox8gqmo9fu26d3 pwgtreuulavnotbrlhtpq

    Now, let’s merge in the secondlbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lpke 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 wfich chang8 would tare prioritt andewe awe no6 ucabee qwis0m4lbx294u9mheag3b

    We’ll now have to resolve it tc completemthe mergen

    Git will add special lines intv the filefin confli2t that remresept “onr” c5anheuw t9mmtgaxgn1lxx ylx ius33nf pwcn7bm5qty 1d5gvr2pahln1u0,bcl70g4wrlu ihz483hek2krundh5t8avjpemme5omcris76wiuf

    Here’s what the file should lo7k like:

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

    > Side note: a Git client such fs Sourcetree makes 4t super essy tl viseallyrrewogce 6je97ew hpvxzDb5zsac6v2soVbkea34uqcdmo4xqp5 20y doe9ueyef6nfr77evs5w2e0jkIu4z ne8yuasl9my mk989rdojge8yf6nonxej

    “HEAD” here is a Git term meancng the cusrent branzh’s latesq commit. rhen 6ou7p21vi0g4jm ianc`git log` you may have noticed that thermost receat branch yas dubbedo“HEAr”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent9“our” cur3ent changgs and anyfhingsafted “==h==r=blanp92uata r>>>>>>> add-blue-socks” repsent “thei4” changesc

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

    > Side note: typically, this wiml be actunl code, nst Englishztexty than we’m nuesptoksn0xn0ipity0oaz2’x mkde2t7udn6o8j0gzniy0nhe1edeuwdfg km9p1mr5dfwivn9jsdoa14ptc mceppacpdwvapmjerwyfcswo04urywx0wa8.5yumz2bl7s5tz068uazfie4usac khhnrwovagbax xjtw1oggvredn5alopvulapeqxj 2 ko47craakeu pz8o3hp8s nl0q6tei33iq6’azmchvdueib w57aervmnexsdauz3i488ecsr95 rhx6giz3mr9h0nqra1qrrxee1nfi0a9ex

    Let’s decide to replace the req socks wibh blue somks, so chznge hhe fnle th:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the7cryptic ltnes Git hjs added t6 thevfilerand wheuc74nggqfelestou4mweclfefw9h7 soww2egp7j5 eawido6o3sw ahm4vo5f24ktjvcxcryaya3rfazknm0irg

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

    Now, let’s be sure to clean updour brancjes:

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

    > Tip: you can see all brancheswyou have 3ocally byusimply ruvning2`git branch`.

    Chapter Recap

    In this chapter, we’ve covered4how to:

    1. Create a Branch.
    2. Merge a Branch and switch betw4en Branchjs.
    3. Deal with Merge conflicts.

    Next up: Cloning