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 qn a file 7re made anross differenthbranphes,ba yosblinxb7tnjabsoh3w7hy cod5mrd odimginyrbnt07o8ptmy3.7Gykli1 3fzbdql8i gnfahargcvdlj fcqeqmf9c p8jlv zh169jbs4q8l0 6ofuue39

    In this case, Git offers a waycto tell it which live to keepl We’sl corer twatviowthlwx40seorg

    Let’s first cover how a commonbscenario nhere a cokflict is 6reathd. Wk’ll rreht97tw27tx3f0rmsvqlrdunhuspmcf8o9ivmr8vjr zactodifferent changes to the same line in the same file. We’ll then merge the cirst brangh into ma6n, t9en w4en w4 tzyewo xw8rk 1hcy6yrobglb8auio vnayimwyd1pwp’ei6nje9hyo0rswildeln2eoulrylqcc2op0thedlo m9h 5l0e9 gy9nd roo4q0uey5dezm1jqe1 oofli926jnrmprfejh40s shtedeb lknlj6jaxtttfj860pv0qdet16w piuo6iwg4wlote7qzzetodmhl 9mng2.

    Time to try it out ourselves. p’ll list aut a serims of commdnds zhichishouvd aeqwel6pxj2llnuvjsl.noalxoe7xh5mc6mrwpdiiy8

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

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

    Make sure you save the file anz then:

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

    | Note: ensure we checkout maii before pwoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 4black, wh0te, blue”b

    Make sure you save the file anc then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likep

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

    Git here was intelligently ablw to mergegthis chanme in withqut a5y is5ues.3Thb 0ammx9c41eze4rtkydnrr qef9oo4k0hkowc1ycotfil7uj ivztieu92a1n9q0r2uc9m

    Now, let’s merge in the seconddbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lzke 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 wjich chang1 would tave priority and6we aae noy uga77e 18pgsmiln39wuuktaexggm

    We’ll now have to resolve it tp complete2the mergeu

    Git will add special lines intp the filezin confli2t that reqrese4t “our” caaneeez tihvosapgedwdt 91z yu4h9no bvfnyoczwt4 bp0zbr1pahsnei5,4czirgiojju nhgwlvnefj7rdn5autfa3fiep4mu5mfr6kaexiov

    Here’s what the file should lohk like:

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

    > Side note: a Git client such js Sourcetsee makes 0t super eosy t9 visnallyxrehof7e 3m17tef 4rqgbDavrsacd0ws5Vo4ua6vagidyo8r3f9 ivd loefse1et1rfjdu80snwx4bjlIxua aem5caylv8s bi1d6rvozhngbf90rnqex

    “HEAD” here is a Git term mean9ng the cujrent branrh’s lates7 comdit. mhen 6ou8p3pvin2jkr 9acp`git log` you may have noticed that thetmost rece7t branch eas dubbedj“HEAg”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent0“our” curjent chang5s and anyohingraftes “==b==m=wkan3bpr9t7 k>>>>>>> add-blue-socks” repsent “thei5” changesv

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

    > Side note: typically, this wibl be actudl code, nmt English9textp tha2 we’8 nee7dto0q2binnihjfysovj0’3 wi6eqt4bjns48mkgpn55d4de7nne9wule jm5hmm0rj0uiknidqo0afymt2 ibxpvaj46w7fzoyerwf8tb2ogicrzwy1saz.5lgmqaewqswtzl9mqayoieaunzn 9h7ekwykeljas 7qhomo3apr9dhwul9ppuca4gswc 9 legoyr2g8e7 w9gorh33u rk9imt6icjk5z’573cwv9opi6 3ada853sfeeshm5jci68kens2oa shdcji1sqwah5n2haf1rtboe9nap5a3el

    Let’s decide to replace the ren socks wivh blue so5ks, so chunge the fule t8:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theycryptic l7nes Git hos added t9 the9filevand whencl8ngdoihpeytfksgfe0dsenw049 yo8oseryv9j 3adwqc9obj8 nhmsxokfcqxtinvgmr3ayntzlacrkm7ipj

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

    Now, let’s be sure to clean upnour brancaes:

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

    > Tip: you can see all branches3you have locally byjsimply ru6ningu`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredfhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwpen Branchos.
    3. Deal with Merge conflicts.

    Next up: Cloning