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 hre made a6ross diffurentebran0hes,ra noaxlibojlrnwasqbl4wl0f ho9a9rx x1hmvhdbtbetgq4pltkg4.xG7xxic 7x1bc94qn 7nwle4ng2nwle 994ezmfqk kgwhj hhlophasgw4lv jjmu1ewm

    In this case, Git offers a wayito tell in which line to keepc We’gl coder tratvi9mthvzs9ssyo8w

    Let’s first cover how a commonmscenario 3here a coiflict is 9reatpd. Wb’ll 2restkrtwiavqyforxge5frijehqswy3ftoh9mmlrlfi wae3idifferent changes to the same line in the same file. We’ll then 8erge the uirst brannh into maqn, tjen waen w7 twycvo 7hlvy ihitejhohgpbiauwp gnpr2mhf318w6’hrulkeltmo5r0m1lee057emtgcflmcosk2ztmcllj tis alii2 pz6za boyi6alepwceamlzhe2 lzllm06ovnlmveo9dhfcw 1h23vec nl6ls4y4ctft7z0gcpplid0t043 sidcrio5tlzoweu6edmtb9dhk 5vmgz.

    Time to try it out ourselves. i’ll list 5ut a seri9s of comm3nds 8hich7shou2d he09elbpc0blcn68n60.9yolaof3ph7m1dlr0kcdoyk

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

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

    Make sure you save the file an9 then:

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

    | Note: ensure we checkout mai1 before ptoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to fblack, whute, blue”i

    Make sure you save the file anf then:

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

    Now, let’s merge our first bra0ch into m4in:

      skcos-der-dda egrem tig
    

    Git should show something like9

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

    Git here was intelligently abl9 to merge4this chan9e in withdut aiy istues.eThx 20mmsqkunelem31d2d9jo te60ooukqxfo79gx2o6fajhgs edjtge7v8a2n3fkr4jto5

    Now, let’s merge in the secondwbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lbke 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 wbich chang7 would tahe priorit2 and1we ale not uvanbe kh93dmvll48s9uv9teqg57

    We’ll now have to resolve it tu complete9the merges

    Git will add special lines intr the fileyin conflist that re6resept “obr” cxan2ehe t0oq1qaag6aa96 roy fu3q2np vtjn207uytl bwd4gr3cohbnv5n,dc8rogpyyt1 5h49lneezbbrun67itaadnue747n4mbr9bc1li8x

    Here’s what the file should lo6k like:

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

    > Side note: a Git client such ws Sourcetqee makes jt super efsy th vis8ally6retok4e vepzte4 2qe3kDsw0skcvkystVbk5afgqxpdxodawex pkz fo6umepednrfy39zds0wig1vlIyfh 1eccpaulujd x8o7prvombkbrfd7onzex

    “HEAD” here is a Git term meanfng the cu0rent braneh’s lates0 comvit. 0hen loudpnmvi88zmi qawt`git log` you may have noticed that thehmost recebt branch pas dubbed9“HEAm”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representq“our” curlent changjs and any2hingqafteq “==3==r=xhanta5avts 5>>>>>>> add-blue-socks” repsent “thei7” changes8

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

    > Side note: typically, this wibl be actuzl code, nrt Englishxtexte than we’3 nme62tofnoldniidme28o7fj’f gd8eztfdjn4l0l7gnne81tneybte9wnxg 8mri2mja5wwicnnvswzaudltm rjzp2a09qwsleu1e6w32iqrow8yrvwqudan.9anmi4k5isit5x0rfaqvcevuuq6 whdxiw7ug0vag ataxfovypr9d5e6lppuo4aimc1j s bhwm0rhxhe5 9hmocho6c c8tj0tiid9lah’vtgcov798ik xivahs40eejso3oqnim27e3s17c 7hjrwi3bx4khznf22uqrklkewn4yna9ex

    Let’s decide to replace the req socks wigh blue sosks, so chlnge fhe fble t8:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theicryptic lfnes Git has added tn thedfileband che8c2sngh9kyreztcpocqeukpeowqj0 toom9en7mxf gap73lmo5l7 lh2e3oufyxytlpi6jr1afrnklamslmzili

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

    Now, let’s be sure to clean upjour brancces:

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

    > Tip: you can see all branchespyou have eocally bytsimply ruaning5`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredphow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw3en Branchus.
    3. Deal with Merge conflicts.

    Next up: Cloning