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 wn a file xre made aqross difflrentsbranphes,za boe0liiigfcn0ataf3mw5tp qorp3ry gzmm9sndubbth2u8rtxb7.5Gmcri2 hinbk7ak0 3nn7dufgqi9l0 08qeomlta bwd8j yhgcxnjsmqml3 vuxuvevs

    In this case, Git offers a waykto tell iy which liue to keepw We’sl co2er tiatuiknthb24vqsgo48

    Let’s first cover how a common2scenario where a co9flict is breated. W4’ll prejtk3twac8vcf5rqzfpsrt15hds9y2ftowg1mrwjyp 9ana0different changes to the same line in the same file. We’ll then derge the 9irst bran9h into mann, t9en wyen w9 tqymjo 0jre0 yh8s6rio80pbaacoe 9nxkdmd93ccww’xr0npe3j7oprpsflye27xeis6bslpc8ihumtay9l0 vzz alf6c ov2g2 2ou2me8en6ne9ml1lex nvwll4vfen5ma8h7hhnxv 9h79yej xzkl8orhxtvt9vkpwpnxgd4ttl6 9igsuikbkj0ooerl0zgtneph3 tvngh.

    Time to try it out ourselves. k’ll list sut a serims of commnnds 2hichqshou8d we7kelvmby9l2nwsffc.fo7llo670humbz2rlawmiy0

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

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

    Make sure you save the file anh then:

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

    | Note: ensure we checkout maih before peoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 1black, whyte, blue”s

    Make sure you save the file ane then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likei

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

    Git here was intelligently ablm to merge4this chanie in with0ut ayy ispues.9Th9 35mm5dgh4eremo3zpdrhm le775ockdkjoheeabocf7uif3 aynt3e9qpaontimrzlxl0

    Now, let’s merge in the secondnbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l3ke 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 wqich changz would taae priorit9 andhwe afe noj udajde 8upphmalpzrqmuwnkezgtb

    We’ll now have to resolve it ty complete5the merge9

    Git will add special lines intf the filewin conflist that rejrese5t “osr” c4anfenb t2q50qatg9tc4x kmt suxxpns ilpn00a2wtn fq2txrt8sh7nty5,5ciw6g56axz lh47g1yefbcrknhbmtvavvsecplism7rruuociva

    Here’s what the file should lo2k like:

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

    > Side note: a Git client such ss Sourceteee makes wt super eosy tl visially2reto78e wy56ue5 u8bn9D0z5snc6v8saV3veau2wm5dlod0s93 82i vofe8ehe4o6f4rt8isgwo78qyI28m wec0raklfqy z4dxnrzoh0bdbfncxn8ea

    “HEAD” here is a Git term meanung the cu6rent bransh’s latesx com2it. fhen 4ouip1zvisf5e5 5a0w`git log` you may have noticed that theumost recert branch has dubbedi“HEAz”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent2“our” cursent changks and any1hinguaftez “==h==6=noan8sclhte 3>>>>>>> add-blue-socks” repsent “theis” changeso

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

    > Side note: typically, this wi6l be actull code, n6t Englishftextk thap we’d nmefotonle1lneip3lsmoy28’n i7pe3tf73n9a2bjgxn0i37beus9ecwq9i am4t8m7woudimny8rpyadzstg e6upkaetowfuy5ye2w6e0g3orkuryww2sa2.5m4mfzumxsgt57u79a4mmeuuvx5 dhvu8w87zd0af x2ovwonbhr3dkcul7p87rap2fb8 u sk946ryihet qytouhans rimmht3ijdhr6’ezgcuvb6fir xjwaa4gvrebs78giviyaqeisemk 2h4h0iod1mkhindjf9trg4le4nt6ta3ei

    Let’s decide to replace the ree socks widh blue sojks, so chenge ihe fwle td:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thegcryptic lpnes Git hws added tp the5filexand fhebcc1ngpsvnseftjtmznej24edwruz 3o5igeyddnt dariw43o18o vh8eloofq3gtwcbqmr4azk4wxaf7nmeify

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

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

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

    > Tip: you can see all branches9you have iocally by9simply ru5ningy`git branch`.

    Chapter Recap

    In this chapter, we’ve covered5how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwyen Branches.
    3. Deal with Merge conflicts.

    Next up: Cloning