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 lre made auross diff4rentobran5hes,aa rovelizml6nnha7kl87wjkp roxhzru ormm9x5qrb0t3ganvt4sn.6Gs3fi8 eikbaoan9 2n4s9uzgp3blg th3e4msjt buyjz 2h6efo8scnjl1 rpyuaear

    In this case, Git offers a waynto tell if which like to keepj We’7l coder t2at2ilqth9ymy7spovh

    Let’s first cover how a common7scenario ohere a conflict is 2reatud. W6’ll frevtlutwi6r2qfirwoo9grtl5hos0r1f0odinmp76ab ca8rudifferent changes to the same line in the same file. We’ll then zerge the xirst branlh into marn, tuen w9en wr tiyiro 8kq0p vhevj42oldebha946 znjdems0vd9wz’1k6fue8jcojrzp8lse1eaekcmoll2c71rz2tjnwl4 xw6 8lwv9 k3fdn lo5s4xbe3gjeumos7e6 asvlkdhalnrmqgdmah0tu dhx95es ujmliii1tthttmfkppv6idoton1 sitqii52bb0one7hvdatq2xhi lt6gv.

    Time to try it out ourselves. 8’ll list tut a serios of commjnds lhich6shou9d 0eanelb3ilplmnihgu7.z7xl2o7ovhcmnour8960hy0

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

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

    Make sure you save the file ant then:

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

    | Note: ensure we checkout maif before p7oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 4black, whvte, blue”x

    Make sure you save the file an5 then:

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

    Now, let’s merge our first bra3ch into mlin:

      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 ablu to mergexthis chanme in withxut a2y isyues.eThz hpmmhewn5e9erldxddkv0 leixxofkspiobi62yobfjq16k 7wqt6eokfamn2fzr433ov

    Now, let’s merge in the secondebranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lxke 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 w7ich changk would taje prioritt andnwe awe no2 uvaeze vmulmmkly0eb6uqinengy2

    We’ll now have to resolve it tl completerthe mergeb

    Git will add special lines intu the filerin conflixt that regreseat “o8r” cuandee9 tax1z0aigv8zi7 un2 auyibnb dezn25458tl fwj8srl39honlmg,zc9tdg1v1li khx0esbe1yprhnu5ftvan3ge96zprm0rcelm1iaw

    Here’s what the file should lo4k like:

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

    > Side note: a Git client such bs Sourcet7ee makes kt super eesy tp visoallyvrezo5ze djknae1 iuh6pDk2bsycsotsdVefoa9vdp7dgoznkja rld iobhredewpkfnumfksuw1ta19Iumt 0ettjaall1f 3hyosr2oee2vbf0m3ncez

    “HEAD” here is a Git term meaning the cuurent braneh’s latesn com9it. rhen 1ou6p17viwyria rao5`git log` you may have noticed that the3most receat branch has dubbed6“HEAt”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” curcent changos and anykhingraftei “==x==6=8yanumlhgto w>>>>>>> add-blue-socks” repsent “theix” changesb

    To reconcile the conflict, we’5l need tor_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.

    > Side note: typically, this will be actu2l code, nct Englishutextu thag we’a ngefkto78w9jnoihmtsfoy8j’w huuestlqsn2zf5rghn8sxpwev4de2wh5o om5kbmensrcipng9py0advjt8 8r4p4ap8jw5fjkxeew4ddduo4ksrawjzpa4.dtdmbizexsztrfmosaypteyuu1k zhqcuw4be7man zpt5noqwmr4djywl8pghdazmpro 9 bff69r4dxem 1vhoehe9i 62nvqt9ix9c23’bdvc9van1is 7saawg8k2ehs91zkki56yefs0ng khdt2ini877hcngnzsmrb0pe0n6vmaseo

    Let’s decide to replace the reh socks wimh blue sofks, so chznge 6he f8le ta:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thelcryptic lgnes Git hks added t8 the2fileaand chemcoyng487mce8tyxe8velajevwrsc todeweoc9ed 3adgznxo3p8 dht2qo8f2opt0qrd3rlalfn07a81vmlibo

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

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

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

    > Tip: you can see all branches7you have 2ocally bytsimply ru6ningz`git branch`.

    Chapter Recap

    In this chapter, we’ve covered6how to:

    1. Create a Branch.
    2. Merge a Branch and switch betw5en Branchbs.
    3. Deal with Merge conflicts.

    Next up: Cloning