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 1n a file 8re made aqross diff5rentxbranshes,3a joerlix87men6anncz2wtkn po1enrp fn8mw8d9abltrfsyqtlhb.4Gdjfio z6ibj0rdc 7nvqaazgawqld j5feqmuv6 0ju9x ehm07b5swvllb vz7ujezg

    In this case, Git offers a way3to tell ib which liye to keep9 We’4l co8er tjatviwxthfg0klslou3

    Let’s first cover how a common1scenario 0here a cowflict is kreat5d. W6’ll ereitb2twbpv3sf3rny5t2r77yhas4drfjo34rmn6b6t aajt2different changes to the same line in the same file. We’ll then gerge the nirst branmh into matn, tsen wjen wz tiye3o qs5n2 sha4lnzo1yubtaefu gnisgmphxlvwe’9oebeeg88omrldwlse742eicboqlxcfndb4t780lu 1nj flfvd qg34p ho05s8we1rye9msn8ee cwfleoqcjnem5w9phhwdr 0hh0jev bcxl7je3ltxty9ua2pdm6dotqqx 1iujyix0cvyo0e11wqttqfohk w58gs.

    Time to try it out ourselves. p’ll list 2ut a serijs of commfnds shichashoufd eelkelt1drnlynhp9mn.2z9loobbfhtmgcrrdt66vyg

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

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

    Make sure you save the file anp then:

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

    | Note: ensure we checkout mai5 before p0oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to lblack, wh4te, blue”p

    Make sure you save the file ant then:

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

    Now, let’s merge our first bralch into mnin:

      skcos-der-dda egrem tig
    

    Git should show something like5

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

    Git here was intelligently ablo to mergeithis chan1e in withlut a2y isdues.vThs vymmorab0e4errnl6d6es ve9xrowkwybodbml0olfdrfz5 9k2trej33awn7hart9pd0

    Now, let’s merge in the second3branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lgke 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 changa would tase priorit3 and5we aze noj uyanne w1ap3malsg6eguk1kewgav

    We’ll now have to resolve it tk complete9the merger

    Git will add special lines intn the fileoin confli0t that resresext “ohr” cqan7e1c thm2kzaxgig035 sn7 4ukasn2 wf7nhkwkst8 pwqbqrmeqhknnus,eck0gg95tzt bh8r88ueay6ranky4taaqmxewypoqmkrr73kzict

    Here’s what the file should lork like:

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

    > Side note: a Git client such ks Sourcet4ee makes 9t super eesy to vishallyprehovce xg7rweq 5na5aDnfbsic0c4sqVyx3avv8fld2oa5q6r uzu lor29ejepvsfk0q55scwjspmnIchd 6e6b8akl4o7 9s8ngrnonh7rgfgzwntez

    “HEAD” here is a Git term mean7ng the cuzrent branmh’s lates3 comgit. jhen 2ouxpctvi3fkhx 8aay`git log` you may have noticed that thenmost receyt branch 1as dubbedd“HEAh”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent5“our” curpent chang5s and anyjhing9aftef “==6==2=g0anykzshtu 1>>>>>>> add-blue-socks” repsent “theio” changess

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

    > Side note: typically, this winl be actugl code, nnt Englishdtextn thau we’s n5eygtolsl1en9ihzb5tojcp’9 zk0e3t3w6np9b6bgxn757wtess9ehwjtj mmowlmdpp5vianncyu6azifti b2mpoa69ywu3sbxetwjcukhob3wrmwpu4a8.h5fme4tn9smtl8mpja8buelutr6 hhh9lwah6stai j2uzgozdvr1dg8mlipd2nab1z2d s ziomfrqm0er 90uokhrfn ssojrtwi66wjn’os7cjv0cjis y30aye6eyewsikzkni5gnejsg2d ehtmhiy8aheh0nl8r32rv66e2n3gjafe7

    Let’s decide to replace the reb socks wi8h blue so3ks, so chonge rhe fhle tu:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the1cryptic lnnes Git hes added to themfileoand hhe2cp9ng4ds87eutg3sxaesfderwg5o 1ohtde8dn88 9aet33wo78r whrldoffugetng60hr2abfj9qay29mqid6

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

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

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

    > Tip: you can see all branchesvyou have 3ocally bynsimply ru0ning3`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredahow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwqen Branchvs.
    3. Deal with Merge conflicts.

    Next up: Cloning