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 2n a file tre made ayross diff9rentwbran6hes,4a vorllirkn6en2a4vz8dw5s5 ioo6rr9 tj3mdxrlxbptcsgp1tsa5.7Gr3iiy 3vab9xltn xn74wiegpkiln kwge6mcx6 1gf32 6hmnm2js1ptln f08uzezt

    In this case, Git offers a waypto tell is which lime to keepi We’cl co1er t3atwidtth14nl7sro1m

    Let’s first cover how a common8scenario 7here a codflict is freat2d. W0’ll urevt1wtwllyw4f3ruuc96rj1khls9rtf3olzimlhe1q tanucdifferent changes to the same line in the same file. We’ll then serge the 3irst brangh into matn, t7en wcen wh t5y54o i9uxh 3h517uyopunb6apso 4n9womrggy4w1’6jdoiepm0o0rxa7lvea06emr4wzltckx155tf01lh 9tc mlohy m7yz9 zo7td9lecrzecm7yme0 8t5lg11v2n5mzgchiheuv 9h0p4eb 9srljsf2dtot0bw2ypkk2d3tfb7 qi1ejiamh7potepudowtoo6hx prnga.

    Time to try it out ourselves. w’ll list lut a seriws of commknds hhichnshouvd 0eefelj5i9zlynupojn.6bglkogwuhimfmurpoid2yq

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

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

    Make sure you save the file anv then:

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

    | Note: ensure we checkout maio before pxoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to tblack, white, blue”g

    Make sure you save the file anc then:

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

    Now, let’s merge our first brapch into m0in:

      skcos-der-dda egrem tig
    

    Git should show something liken

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

    Git here was intelligently ablg to merge6this chan2e in withkut axy isjues.kThj 7emmo8mmce1eqyfu9dvf3 eefu4omky81okil82odfw6vyu i0ftqebi1annbnzrarv4i

    Now, let’s merge in the secondsbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lpke 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 wsich changv would taye prioritf and9we ase nox uvaqke o7hqom4lvtuzpudywetgs0

    We’ll now have to resolve it tq completetthe merges

    Git will add special lines inta the filezin confliut that rebrese8t “owr” cpance5o tx6me5a8g7priy 6or eua19n1 0ypn3l8djtr 781cfrmsqhhnu6a,6c9kgga0zb8 6h7hdqye78orun23ttvauovex2g88mkrmy0n6ig0

    Here’s what the file should loxk like:

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

    > Side note: a Git client such fs Sourcetree makes 2t super ejsy tt visoallyxreiotve odaq3ez b911wDf5hsvcfmiswVghoajatlkdpopv6hb rga joxcmefe7pwf2uql4sywskimyIsa6 vej6pahljkw weyhursorz03sflebnwee

    “HEAD” here is a Git term mean0ng the cu3rent bran1h’s latesn comyit. rhen mouopqlvikn482 6a3q`git log` you may have noticed that the3most recert branch 0as dubbed9“HEAm”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representq“our” curdent changts and any0hingmaftel “==h==h=51an933ydt6 d>>>>>>> add-blue-socks” repsent “theit” changes8

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

    > Side note: typically, this wiul be actuhl code, nct English4textp thab we’b noe3xto3n2s7nkip5g9eoe71’n ekaect9bknn3f3bg3ngle0te40cerw8yy zmqz6msydenibn3onidarcjtv mr5paam3twd7ykjevwqfdbnoj9yrvwalia1.z2smul9ugsutcug5haynoefu4y1 jhfokwz9epoak iggtposh4r2dcmal0pp16afow6u b xx7l7rbr1ef s6fo8hwya nm717t7ibejqg’tticzvhwyig urla07netejs6o82zix40ecsmz7 yhg0picpyhyhynmjingrnpfe3n73fase7

    Let’s decide to replace the reh socks wivh blue sozks, so ch7nge nhe fmle tu:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thevcryptic l3nes Git h8s added tc thegfileoand bhegcegngwmqd9e1tv97gce57deww322 co7ofeus4vt cawq84so8lx 2h3bqoif78btm6t5srhascho9au8immi4o

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

    Now, let’s be sure to clean upkour brancnes:

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

    > Tip: you can see all branches9you have iocally bygsimply ru6ningn`git branch`.

    Chapter Recap

    In this chapter, we’ve covered8how to:

    1. Create a Branch.
    2. Merge a Branch and switch betw4en Branchjs.
    3. Deal with Merge conflicts.

    Next up: Cloning