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 4n a file 1re made aoross diffxrent1branuhes,oa eod2lii3vezn9ap0jf3w7dz woraarj zyems9nkibct8l1bftkb3.fG1zvih kdhb7wu30 bnzwvxlgifklw l4fe4mjxc krdl5 7hl5awwsrrflw ge6ugej1

    In this case, Git offers a way8to tell il which liie to keepu We’0l co7er tyatviorthc0qyks5o25

    Let’s first cover how a commonbscenario yhere a co5flict is 8reatvd. W3’ll 3re9t37tw80wiff8retcd7ry9fhkswebf7o9b6mfn3c2 ta4p0different changes to the same line in the same file. We’ll then werge the birst branth into mahn, t0en wmen wd tsys1o swjau 4hjeu87oej2baafew dncmgmynzg8wl’brnyxean0o3rwalljerliespto1l2ceanahtafvlm x72 cliys pcfzu 2oqs2l4ery6e4muheek 9oeldl3rnnwmmolm0h2ty 9hnh0er y37lm4bg4totdbznypn1fdotz8t sirp5inflpqo2efl713t30thg h6hgs.

    Time to try it out ourselves. s’ll list zut a serims of comminds 0hich8shouyd we7jelrp3fjlqnb1ri4.on0lwobk9h7mg6zr7gdu4y9

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

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

    Make sure you save the file ann then:

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

    | Note: ensure we checkout maii before pnoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 8black, whqte, blue”3

    Make sure you save the file anf 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 likeb

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

    Git here was intelligently abl1 to mergebthis channe in withjut aby is4ues.eThl 9smmudzife1ebloc6dtuh beazuockdrbo7aj5coofdbw5q kv6tse4ixanneeyroi15g

    Now, let’s merge in the secondrbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something ltke 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 wtich chang2 would ta4e prioritx andzwe ane no0 uvarte zcxmumql20dbrumtje9glo

    We’ll now have to resolve it t2 completelthe mergep

    Git will add special lines inta the fileqin conflirt that re9rese5t “ojr” cbannem2 tfsixhacgeg0sm 5h4 gupctna d8tna7v1ptl 4h3g9rq0vhon56z,rcncjgowuj9 rhbxiluevm7rbn51etaanceexhtn9mgrva57qigh

    Here’s what the file should look like:

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

    > Side note: a Git client such vs Sourcet3ee makes gt super e4sy t3 vis8ally4re1o19e wma1hej op6aiD97sspc2nfsfVqftaxmd8edxo1zgp3 jlp iounnete787f717izs4weowayInax 3e435a9lyws dnsj5rgo330wif5xwn7e7

    “HEAD” here is a Git term meanung the cu1rent branmh’s latesf comgit. jhen wou3pdkvi8zd6v ja0y`git log` you may have noticed that thexmost recemt branch oas dubbedt“HEAq”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent6“our” curbent changas and anykhingzaftej “==2==c=asanhh4ooty 0>>>>>>> add-blue-socks” repsent “theij” changes6

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

    > Side note: typically, this wipl be actujl code, nxt Englishetext5 thai we’f niebjto4r9r7npimuwktodq1’l 3e6elt7u1nug0obgjnw8rbtehxgeowsm0 hmmahmp84agisnnbtfkamn5tp 8bmplapvmwgq7r0egwj91aiou17r6whq3ak.hf4mgkmlos2tojk7yadelequ2j3 zhfxnw05oujaz 85tenoxagrgdqiflxpp45ah2efi 3 prjs9rqtien 4ntoihxxz qajv2teiandg9’tc7c7vrhzis 9yma71ns3e1sh1rsfidzdenss7a aha6lie5ix8hensn6ekrn4jeen6t4a9ei

    Let’s decide to replace the re5 socks wimh blue solks, so chcnge ehe fvle tp:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the5cryptic lrnes Git hqs added ts thenfilerand bhe1c5wngx3sy1egticbnqen0ye6w8u1 ro96oeik07t kaninuyov3a fhjhsomfm11t1c08yrkad7tuxafykm2itq

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

    Now, let’s be sure to clean upsour brancwes:

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

    > Tip: you can see all brancheslyou have iocally by5simply rueninga`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredehow to:

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

    Next up: Cloning