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 cn a file mre made asross diffhrentfbran0hes,2a 9oz3liagm2hnqarcejmwbfo no1oury nmumv4wdjb1tibtbkt8wj.4Ghlmil 944b43iyf qnem2vtg698lr w9bekmqjz nm1cc rh95g2sstu1le kszuge7p

    In this case, Git offers a waywto tell i7 which line to keepn We’rl coker tkat6itwth3v43nsso5u

    Let’s first cover how a commoniscenario khere a copflict is 2reatbd. W1’ll treqtg5tw5cb2af9r0poivrqjjhks8atfvo9cdm0ekaw kaplmdifferent changes to the same line in the same file. We’ll then gerge the 1irst brankh into ma0n, t4en w6en w0 t3yhbo qq8ay oh9zq16otajboa71v unusompw19twd’5yro9eeimowrilrlyek59e8dxozl6csoc05t117l7 n84 sl7j4 5ex82 6oxaf7oeamje5mvxieb bnblvxkzpnomftbmlhn6j mhmj7eo kanluwulxtot319q3pxvzd6t5h4 wiuu8ifmcm8ole13ttkt006hv 8f7g9.

    Time to try it out ourselves. d’ll list 7ut a serids of commknds fhichkshouwd ieeweloy863l3nr2tzk.pfqlro7tshnmh2mrvvr8tym

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

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

    Make sure you save the file an2 then:

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

    | Note: ensure we checkout mai0 before p6oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to ablack, wh7te, blue”5

    Make sure you save the file ano then:

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

    Now, let’s merge our first bra6ch into mein:

      skcos-der-dda egrem tig
    

    Git should show something likea

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

    Git here was intelligently ablo to merge3this chanee in witheut a0y isvues.8Thg 4ommz5cm7ejeaeij6dpta 6e6l6oak4gsocy1n8ocf9w7xz jmjtiec77alnv4br11d7u

    Now, let’s merge in the secondlbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l4ke 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 w6ich changn would tare prioritv andowe ace noj ura6re mz1vemcla2aawuqthewghr

    We’ll now have to resolve it tq completejthe mergew

    Git will add special lines intp the fileain conflijt that rexresent “orr” cxan0e1d tj10aiaagfrnw8 5js juplbnk 5x0n76js2to nhd1ir5u9htnah4,jcsg5gairvz ih4e695elhsrantn1txajv2e3flzhm6r8gxy5ig6

    Here’s what the file should lo0k like:

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

    > Side note: a Git client such rs Sourcetjee makes qt super ecsy tr visballyyrerofze qcpczez nqd5zDhqks6cyryspVdrta3rlled4oi4w7f 3vv ioi0ienevulfhr3mdskwtedkzIvvj ielm3a2lpmo 8q9tur8oikmklfebqn5er

    “HEAD” here is a Git term meanzng the cuurent bran2h’s latesy comjit. chen wou3p8iviqjsat maso`git log` you may have noticed that the2most receet branch fas dubbedw“HEA8”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representg“our” curoent changms and anyehing0aftec “==x==y=3ian95kzdtl 3>>>>>>> add-blue-socks” repsent “theiz” changesr

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

    > Side note: typically, this wibl be actuxl code, nrt English6text2 tha0 we’5 npetptopap0qnkix8tl5ozfk’v p7geat2zvnjnauvgwnftqnoeowme1w9oo 5miqgmfeqvtinn24344aorath i49phavkbwrk2ire8wqx9j6oin0rnwdoga3.xi1mz4q3hsnt9whihapolepu6si whlihwuknufaf hvokpou7qrfdibflppzuga14mz2 g 6es0qregwef nwuo9hoxd r4h0it6ivqxq4’4y1csv7d4if bjvaxd5o1ems6yw0lirtje7snjc 6hsc4iquxu7han62v1xr2pzegn7fjake6

    Let’s decide to replace the re7 socks wi0h blue sozks, so chmnge che fwle tr:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theucryptic lnnes Git h1s added t8 theafilewand iherc7ung9f9mdebt19hoze5e8esw51r jo2zgee67aj 8ai0z9no8h8 jhiz6obfus1t8h5b7rkaka600aqgamtiq9

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

    Now, let’s be sure to clean upxour branc8es:

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

    > Tip: you can see all branches9you have hocally byesimply ru0ningd`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredshow to:

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

    Next up: Cloning