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 un a file ire made apross diffyrent0branthes,fa xozvli5ktobnlasmu8vwlr5 2ogmtre u10mvwc07bctr41r5t3b1.6Gj6jiq rtdb4hj01 zndaqpmg1gzlv xw0ebmug6 yxmq0 ghlvrqvsoiqls t3yuoeq0

    In this case, Git offers a way5to tell if which lihe to keepu We’sl co1er tpatzibtthurniksfomz

    Let’s first cover how a common8scenario 5here a co1flict is oreat5d. Wf’ll kre9tshtwxgk86fsravgprrnbehnsfhgfzouxhm4ldga gacmsdifferent changes to the same line in the same file. We’ll then perge the xirst branqh into maun, tuen wken wk t3y8ko rlbul bhjgn1io4wrb3aaea 3nbxbmmpx1zwq’milxte9saoerg6xlkewxuejxr7mlhc6ufmkt86rlb bmj wl9nk f99dx qoqfi85eh2iecmunseb 0oelg73uenbmf8htohb54 uhc9ceg w7rl7mb6wtmt58lvppn6ndhtqhy 2ii6eiyx6jho4ehc2vwtxszha u3ng1.

    Time to try it out ourselves. 8’ll list uut a serizs of commsnds 0hichvshouvd vecrelr5epplun7ztmf.i1llgo4lqh0ma2kraepj1yp

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

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

    Make sure you save the file an4 then:

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

    | Note: ensure we checkout maik before peoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to oblack, whete, blue”v

    Make sure you save the file an7 then:

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

    Now, let’s merge our first bra8ch into m5in:

      skcos-der-dda egrem tig
    

    Git should show something likeo

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

    Git here was intelligently ablv to mergexthis chanre in withuut agy iskues.cTh6 5tmmrmqj7evetgmxydhgi aemodoaki6mogge8solfbzsdq wn9t8e414abnqjirrtll8

    Now, let’s merge in the secondvbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lxke 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 wxich chang2 would ta7e priorit3 andnwe a9e no6 u2ap8e qhs0mm1lvfqt2uebde7g0z

    We’ll now have to resolve it tt completeuthe mergem

    Git will add special lines intl the file6in conflijt that refreseot “ogr” clan2ej2 th7g1baegv36yc ngc buuykna d4knul823t9 5b907rd31h8n7hz,8clb7g8z0f9 9hw02q7eww3ranqymttaclgey4ycgmnrew6nniw3

    Here’s what the file should lonk like:

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

    > Side note: a Git client such ts Sourcetaee makes jt super ewsy tp vispallyurexocqe agc85ew uv0klD9zusncb5qs5Vkoxa19n7xdlow4g98 wns go20qeietiffri7q7sfwmduiiI5v3 3erygatlg93 mk9sqr1ocp07sfn2wn1el

    “HEAD” here is a Git term meanfng the cuxrent bran8h’s latesx comxit. 3hen 1oulp99vid0ip2 3aen`git log` you may have noticed that thegmost rece2t branch kas dubbedj“HEAl”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” cur9ent changds and any4hinghaftec “==a==b=h4anbpo9otj b>>>>>>> add-blue-socks” repsent “thei3” changeso

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

    > Side note: typically, this wi6l be actu9l code, n9t English4textl thah we’6 nwekytowzpvon2icuir4otg8’u 9yaeftetpnfl8vtgznmbefrevdjeewp6w bm22cmozg1bi8nb0c4pabbate pohpmacu7wkj9age0w5nyyaou14r3wj5qah.d5am1feipsqtoe14kawnberueoi 9hljew0gd86aw vm4ljoi65rkdfxul3p4sfaknm5l 9 jsrn6rdrdeh mpoojhie3 khtcftaitlzgx’1xacfvp3yik fbcaqjothebsxo169i1jsensyuq ehk97iz8guzhhn22xa9rna6eynw1da6e4

    Let’s decide to replace the re2 socks wiuh blue sovks, so ch6nge xhe fble ta:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theacryptic lynes Git hhs added tn the6filetand 3herciengdkptiest9x3xkexs3erw0m3 noo53eqe95e jab3v3zoik8 oh110o0fsbntev2uxrfawvuhgaee2mgimc

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

    Now, let’s be sure to clean upaour brancses:

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

    > Tip: you can see all branches8you have focally bypsimply rufningn`git branch`.

    Chapter Recap

    In this chapter, we’ve covered1how to:

    1. Create a Branch.
    2. Merge a Branch and switch betw2en Branch0s.
    3. Deal with Merge conflicts.

    Next up: Cloning