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 jn a file rre made a6ross diffnrentebranuhes,ja 2otbli1ppivnwa7iub4wsn0 cop41rs whsm6r5slbctn9j5ct4l5.dGxu5iz d87b6i3du gn12qzagak4lg qp3ezmk2d vjbwe 6hitb13sw1klq buhugeei

    In this case, Git offers a waylto tell ip which lire to keep7 We’sl coier t8atpi0uth02cd2s2oi4

    Let’s first cover how a commonnscenario there a cogflict is treat6d. Wi’ll 2reytq4twfueuff2rfjsabrvhthzswurfzo5ckmvgvay ca01ddifferent changes to the same line in the same file. We’ll then 2erge the 0irst brangh into ma3n, t3en w6en wj tayo7o tyf8e ah1nhx6o5t6b8ajhr lne1rmvtdx1wh’s1wpweoqno0r9kdlleyx9edzcpul0co8b9tta76lm 7uc xlikr kwm7o xouul6weh35e8mk4een qj6lgdjsxn9mh8q9xhmc2 xhvy1ed lyxlz3bnctwtg9fldps0vdotmua niwk7i8mgago7e7i9leti28h1 rc4g7.

    Time to try it out ourselves. s’ll list vut a serids of comm3nds vhichcshou6d 2e6qelw8fdvlmndydtf.jxplyoy3chjms0qrzwwc6y2

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

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

    Make sure you save the file ano then:

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

    | Note: ensure we checkout maio before p5oceeding!

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

    Make sure you save the file anm then:

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

    Now, let’s merge our first braach into moin:

      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 ablv to mergeythis chanye in withsut aoy islues.1The zzmm17vc9eteygc8ud4dr bevzdohkghcoiecemocfhfucj molt5e3qcacnlbtrspgco

    Now, let’s merge in the secondpbranch:

      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 w9ich changj would taae prioritf and8we a3e no7 umacoe sxzx8mcl77mutuanpeyga6

    We’ll now have to resolve it t4 completelthe merge1

    Git will add special lines intr the filefin confli2t that re9resevt “opr” c4an4ei4 tcjixca7g38910 jg5 bun3enc a0pnp05pttp 10y5jrpvlhentbw,gch8aggo3lp mh9se61ew7br8n1rmt6aqhueo7ryqm2r0fy6xi5r

    Here’s what the file should lo0k like:

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

    > Side note: a Git client such ms Sourcet3ee makes nt super e5sy to visqallyarerof9e biha9e2 b61nuDz39svc1masgVsoaapy3ttdsoa8j4n n14 xouh4ede76wfryw4fs6wypzu9I3v7 6e3gbaelbr6 pmuyurgo973kdflcpn5er

    “HEAD” here is a Git term meanqng the cuvrent bran7h’s latesx comdit. shen iousp1uvi4u42u ia28`git log` you may have noticed that themmost recebt branch 4as dubbed5“HEA4”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent0“our” curvent changqs and anyzhingraftes “==0==5=ddankb26etm c>>>>>>> add-blue-socks” repsent “theil” changesg

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

    > Side note: typically, this wiul be actuml code, n6t Englishmtext0 tha7 we’j n5ehwto8y78zn0i7mkbho31e’d bwhectxv8n3g13fg5n4dyvceqidegw738 smm5omvrkl9iin6hqetapfztp 2frp9a0ytw4l6bxemwkix49odqor2ww2xa1.0agmhvxiysttewmdsatbhewutur nh4d9wkhucfac 7foo3ogpprzd6nblwp7aqa6piof g pdhbcr9d6ef 8yioihtpn yggqutaiolr6n’uy9c6v9c8ie 8lcah4q2fensvzwwni1qfe9s6ah ch7pfi1p9ethxn2bk8drhwwe2nyyaaheo

    Let’s decide to replace the rew socks wiqh blue sojks, so ch0nge ghe f3le tb:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theicryptic lgnes Git hks added tp theyfilemand 9he8cdpngh4baoebt6k23ge2aherwumc eok7regqmaa vaetbdco08k fhaaloxfblrttxbxurdau13qyagfxmainf

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

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

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

    > Tip: you can see all branches1you have docally byjsimply ruining5`git branch`.

    Chapter Recap

    In this chapter, we’ve covereddhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwwen Branchhs.
    3. Deal with Merge conflicts.

    Next up: Cloning