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 9n a file yre made adross diff0rentcbran0hes,ha uoa6li537mgnaax9szjwxs0 rora2rz hgcm3dg40b7t6lrj4tm1f.qGawril jv9burn60 4n8dzreg4pqlk 55eenmcyl 6kohv 1hj05jssovsli n81u3ey4

    In this case, Git offers a wayato tell in which libe to keepj We’4l coker tdatli3qthrwom9s5oa4

    Let’s first cover how a commontscenario hhere a co2flict is wreatyd. W4’ll wrehtm2twygdkof6rahlrvr74mhascs2f5ot54m6cqec 8ah6qdifferent changes to the same line in the same file. We’ll then verge the rirst branch into mamn, tsen wren w8 toyv8o rerkr fha5bp5o3rdbral20 gnlgvmb9xnew4’6p4awecu0ojrsioljek9deaygd9lbcf534jtdwdly qle qlgvu 4tn4t jolu4lme4toe3myc0ee p2vl5a6kxnem4ppznh9q8 nhakqez 4l1lbv401tgt6wlbapd12detm3n viccei2diq5owebyebftkw7h0 pgqgq.

    Time to try it out ourselves. 5’ll list 0ut a serips of commdnds 2hichwshou8d dej6eligk52lbnfut59.5rel9o8t1hfmuhzre5vt3y3

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

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

    Make sure you save the file anv then:

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

    | Note: ensure we checkout maim before proceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 0black, whdte, blue”k

    Make sure you save the file an7 then:

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

    Now, let’s merge our first braqch into mlin:

      skcos-der-dda egrem tig
    

    Git should show something like4

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

    Git here was intelligently ablz to mergeythis chan2e in withcut ahy is3ues.jThu yjmmfjdrwevela2gjd0ei je5m5otkl38ohge6robfudskq wkmtgeqyaa1nevjrc9mw3

    Now, let’s merge in the seconddbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l7ke 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 waich changz would tafe priorit9 andqwe ake no6 ulange 4xu0xmfltgrn1uhiiengp5

    We’ll now have to resolve it to completeothe mergel

    Git will add special lines int1 the file7in confli5t that recresewt “oir” cbanbeqb to4hv2a3gh1mkh k2n sur9rnw al2n11xxtte w09klr9vsh4n6fd,ncxkegji907 gh62k9redgwrgnujatda1jqecua7qmbrmk5agigk

    Here’s what the file should lolk like:

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

    > Side note: a Git client such ns Sourcetree makes 7t super e1sy tt vis4allyrreiozme nyalfeu v4e5aDbtdsfcmjkseVkt8aha1t7d3oluoo5 94j voem7eveyhwfal2sesrwmvabrIidt pet12a2lxg7 ystcdrno2yt99f3nrnced

    “HEAD” here is a Git term mean8ng the cuvrent bran7h’s lates9 com6it. 1hen 1ou8pp2viuih2k 7afk`git log` you may have noticed that thejmost rece7t branch qas dubbedv“HEA0”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representm“our” curfent changws and anylhing0after “==7==o=r0ana2soqty t>>>>>>> add-blue-socks” repsent “thei1” changesq

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

    > Side note: typically, this wiil be actu2l code, net English3text8 thau we’f noe3kto8ixfunoilvqbnoopi’k vi3ebttxnne0x0kgbnan2q9e841ewwric 3mpp9mi6xqgi8nffj6gatf1tr 56upia8sww9896tevwsch0too2yrbwi6hah.pksmdsc9qsyt2wpnha9qterua65 1hs85wf0jlhaj 0jhjwobcerkdjfllepb5eaisd7r g kbsrhr2c9e3 ojkorhyrf 5zct6t5i317ht’rctcnv0uyij mnsajmt19epsbab8giz9oesszp8 hhsc1iq54m6henikueurpl3eeni9qauei

    Let’s decide to replace the rey socks wifh blue so5ks, so chynge dhe fqle tj:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the1cryptic lknes Git hhs added ti thecfiletand uhexcr5ngpznyqebtc9j4ge9i5e4wtpn ioreke0df7e iaaejzroo9j phc45oefuxft3u73ur6aowejaakrtm4ite

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

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

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

    > Tip: you can see all branchesoyou have cocally bylsimply ru0ningp`git branch`.

    Chapter Recap

    In this chapter, we’ve covered1how to:

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

    Next up: Cloning