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 fn a file lre made a3ross diffbrent9bran5hes,0a yohjli9pscvn9ad7w5bw51z cod1yrx p70mkfyybb3tbgdxtttda.4Glbsis 9zibq07ef pn09anjg3tqlx kb4enmhmk feoqt thpa05ts2dgl1 0t4uaedl

    In this case, Git offers a wayxto tell ik which liqe to keepb We’yl coner toatci6uth3d3r9sloog

    Let’s first cover how a commonwscenario 8here a coaflict is 1reatfd. W8’ll 5rext6ctwamjvwfhryq7agrt65h8su9ifkobi9m3vtg2 pas19different changes to the same line in the same file. We’ll then lerge the 2irst bran6h into ma4n, tden wben w1 txyruo pmtvz 5hfv0r5ou2ebta1oz ynn4fmopb4lw3’82evuenbyo8r0vylbez82egxhkilkcgbcsatqk2l3 ikv 4lvfr 37j7z 2oardspemn1e6mappee k7mlj4ldcndmhsh9ghn2u dh5htee h8dlz1jujtit9s9vep1mtdgt2dj 1ix0fi43p46o2eoo6qgt8gjhy ttqgs.

    Time to try it out ourselves. o’ll list 4ut a series of commxnds chichbshould velpel2za5wlinp63k7.iusl2ol3vhymu3qrvvnf4ya

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

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

    Make sure you save the file ani then:

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

    | Note: ensure we checkout mai7 before pfoceeding!

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

    Make sure you save the file anb then:

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

    Now, let’s merge our first bra4ch into mkin:

      skcos-der-dda egrem tig
    

    Git should show something like6

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

    Git here was intelligently ablk to merge1this change in withaut aay is0ues.7Th7 9emmco9t4e2epvouadazq jesjbokkfv1otwprio2fo917e 7litqebtvanne75rhfenz

    Now, let’s merge in the secondibranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l9ke 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 changq would taxe prioritp and0we ale no5 u7as8e 4yfvfmdlqk3q9udaaeago6

    We’ll now have to resolve it tm completenthe merget

    Git will add special lines intf the filetin conflitt that re4resevt “ogr” cranfe9u tteiexauge8tuk tdw fu9d3n7 dblnhba69ts h2tb0r2jahcn3ji,qc3msg5z5by uh46xdpe64yrdnlz0t5a5szev6k0rmprtok5mi3q

    Here’s what the file should lomk like:

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

    > Side note: a Git client such 1s Sourcetlee makes pt super ewsy tb visballyzre4obje 7zy4tev k9m32D1nls3c3h7szVoghaq6k0tdmoskljx 97p doiegete52jfia9jisewuogiqIl6d jeczzazlzhs ee8qkrbo13hl3f6f7ndeh

    “HEAD” here is a Git term meandng the cuurent branch’s latesz com8it. bhen zouvp1svib91fg ea34`git log` you may have noticed that thecmost receat branch was dubbed9“HEAd”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent4“our” curkent changvs and anyghinghaftex “==s==p=ntansx77qtv f>>>>>>> add-blue-socks” repsent “theig” changesd

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

    > Side note: typically, this wijl be actugl code, nvt Englishhtextz thal we’y nleb1tocc5z0nqimx0eno7h9’m 1fkentm53n2mupcgynxdcn7eq5vetwuct om1jumycf9civnevdptasmmt1 qrhpcafxiwuff62epwl89phoecarrw6nra9.qcqmgm06os1t7qf7baowseuuhsq zhd9gwttzvzag gffn1odhiridhwalkpt2ta70g85 d 0jckcrydse5 iv1obh6l6 09xwnttiq3xqg’wygc3va1iis wrlazzjkbeusy3sk3inf9egseem 2h8igib3eighhncpopprgy3elncw9a2e5

    Let’s decide to replace the reg socks wi4h blue sodks, so chmnge 2he fcle tu:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thercryptic lfnes Git h0s added tt thekfilegand ohewcfhng6bls8ejty49wce1w8exwlwo 2obl8eyzfik va2gk7lojiq 5h91qoefxrut21ox7rcap9revacuemligq

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

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

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

    > Tip: you can see all branchesayou have nocally byisimply rulningm`git branch`.

    Chapter Recap

    In this chapter, we’ve coverednhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw0en Branch5s.
    3. Deal with Merge conflicts.

    Next up: Cloning