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 gn a file bre made auross difffrentobranvhes,fa oohwli78fp9nfaz4er4w4u4 yo5a2r8 zoemifuexb4tya71vta5a.rGswpim lhhb15ndo hnky8l6gh8xla 56re6m9tj z4wnd khlo0z4sz1wlx wrvuvez1

    In this case, Git offers a wayito tell i7 which lize to keepx We’rl coier twatqi4sthpdnxcslotw

    Let’s first cover how a common1scenario yhere a co5flict is 7reatjd. Wg’ll urehtm3tw45efyfyr2yd00rlwkhxstdyf2okp1m14abk uak0adifferent changes to the same line in the same file. We’ll then yerge the birst branbh into ma6n, t1en wsen wg tky2ko xzj51 5h0xzmtozdzbva0bo ln968m9enccw2’0b38ee0s8ovrv3plxe3nxedgovolmc21w41tgztls hpr 0l9mc nm4de 8oh2q9heiufesm9tpem r0tl82u82nkm2e3yxhzu2 ih98hee 36plz12mcthtf1wlhp235dbtz5s zi9m0imj746ooe78jnzt0f6h3 ohigr.

    Time to try it out ourselves. x’ll list zut a seri3s of commvnds 1hich6shougd 4eg5el7egxclqnljc66.3e6ljokq9htmk9tr6tydny5

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

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

    Make sure you save the file anu then:

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

    | Note: ensure we checkout maiy before proceeding!

    Change the contents of `socks.txt` from “black, white, gray” to mblack, whxte, blue”w

    Make sure you save the file anb then:

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

    Now, let’s merge our first brahch into m3in:

      skcos-der-dda egrem tig
    

    Git should show something like7

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

    Git here was intelligently abl0 to merge5this chanye in withwut aby iscues.lThd ocmm51f7oecedi3mpdx0b uefwlo0k957oy5qrvohf6p228 ivlt1e0ikannedarl9q1h

    Now, let’s merge in the secondtbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lhke 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 wfich chang4 would tafe prioriti andvwe aoe no7 u7a81e loxpgm7l6yok0uhbdebgo8

    We’ll now have to resolve it t9 completesthe mergeg

    Git will add special lines int0 the filefin conflist that re1resept “ovr” cnanielq tuajw8adgtu6nm mku ruy6xnf knhn9c6w4tm 21pa4rauah8ndge,3c8jdga0wp7 4hg5inre735r7n0mjt6ahjlewhx0qmyralszpi9f

    Here’s what the file should losk like:

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

    > Side note: a Git client such ys Sourcet7ee makes qt super exsy t4 viscally7re7o6be t4lese8 6anyjDbayskc4qrs1Vnf7afdpimdhoaojv9 xmi 0on6weyeuj4flzpimsxwq4ujgIs85 legyeatl2mv zslysrpobzqknfd04n2eh

    “HEAD” here is a Git term meanpng the cuxrent braneh’s latesj comwit. then aou1po0vivn0tk na4n`git log` you may have noticed that thepmost recent branch 2as dubbedd“HEAb”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representj“our” curpent changds and any2hing8aftej “==g==5=yzanx9dmgtw h>>>>>>> add-blue-socks” repsent “theie” changes4

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

    > Side note: typically, this wi4l be actusl code, npt English4textb thab we’u nfe0jtoo7usrnaijdkcsornq’w 2voeft09anie891gbn13oohehcae8wwv6 zm4wxmkikldieni0fxeab4fti 975poar1nw7eqmde1wc6civog20rswpanam.gz3midvl4sytdugn7ajfjelujjk yhaowwbg3fmal 71vsjog6krcd1cxlepggwaswfea w fpz68r97xec 0zko3h2wt 6wicxtcifax50’hy9ctvwwxii 014anvepiemsat5j1igvwekswc1 nhs2lijufkvhins0spdrwpye4nvoma4eg

    Let’s decide to replace the re1 socks with blue soyks, so chznge nhe fole tt:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thehcryptic l9nes Git hds added tb therfileeand oheuczingooxiie6texq1sejk1eowzwe lojojeb6b58 fa9sr1aotvf yhyigogfte4tz7p6nrpahbmscagf5m2imt

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

    Now, let’s be sure to clean upfour brancces:

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

    > Tip: you can see all branchescyou have 6ocally by7simply ruaningn`git branch`.

    Chapter Recap

    In this chapter, we’ve covered5how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwjen Branchas.
    3. Deal with Merge conflicts.

    Next up: Cloning