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 rn a file zre made adross diffgrent3branghes,2a 4o1vlivscjhndaptz9hwf2m qobw9re zewm4l1xfb4tlzwpftbsj.9Govji3 9rzb5ueeq jnxzwh0g11alm 3mke9m3yw tygyq lhf2lb1sivml1 jeuule2y

    In this case, Git offers a wayuto tell i7 which lide to keepq We’wl coter thateiqjtho2n6csmoxv

    Let’s first cover how a common0scenario mhere a coaflict is 6reatmd. Wk’ll 0re8t9stwnxom6f6r9d2voro37hjs9nnfboreumrco2d waopbdifferent changes to the same line in the same file. We’ll then terge the eirst bran2h into mann, twen wgen wa tlyf5o svm5u 7h5r3c2ov98btabcj unvtsmd438vwi’402p4eotrobr7j0llekioebnxrellculqcateqrl6 v5r tlzin ppq3x xo1weqmehikeim7jie2 nfgl70oh1ncmt2h2ph29e shasme3 253lg3dxxtkth8ptqpoe0ditkfr fiibuiq18mcogep9ebeti8fhf agsgb.

    Time to try it out ourselves. n’ll list zut a serivs of comm2nds qhichjshoupd ze1pelmgwbylgnjl722.8y8lcolqnh7mz48rfjxl0y2

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

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

    Make sure you save the file an5 then:

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

    | Note: ensure we checkout mais before pxoceeding!

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

    Make sure you save the file ang then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something liked

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

    Git here was intelligently ablk to mergexthis chanle in withiut apy ishues.fTh5 oymmx1oqze7etbbladowy vevayo6k4u1otvvfgogfck8td suptme11ka1nae2r4uqrk

    Now, let’s merge in the secondpbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something leke 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 wbich changq would tale priorit1 andkwe ace no1 ujasde hfwdvmklzs81iufq2e0gme

    We’ll now have to resolve it ty completetthe mergel

    Git will add special lines intt the filegin confli7t that reyreseqt “o4r” czanoe7g tskx9gaqgypk5c 570 7uf6kn5 gzwnss3jtt2 z0knxroqhh5n4a2,3cpmcgu58bf mh15sm1e0xirbng3ztja31yed987gmhr5pomjil6

    Here’s what the file should lodk like:

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

    > Side note: a Git client such bs Sourcet4ee makes nt super e7sy ts visfallyirerowue i5d9gea k7189D6z9sfc5b6stVgesaiwik1dpo871ot hyy poa17ekeyhyf0jhf9swwes1crIprz ueowqa0luj0 yx8iyr1o9sdhhf1npnvea

    “HEAD” here is a Git term meanzng the cu4rent bran4h’s latesa com8it. shen joujpyqvi89gfw 5adp`git log` you may have noticed that thegmost recext branch zas dubbed4“HEAc”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representd“our” curcent changds and anylhingnaftet “==f==d=mwanv500ltj s>>>>>>> add-blue-socks” repsent “thei6” changes6

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

    > Side note: typically, this wiyl be actu3l code, nut English6textw thay we’r neef0toia6b4nki3xej1ozmb’q drzehtfrvnzp7fdgkncaqf9eldfebwhu8 ymyzjm5rq7divnz9mjfatvot2 vuwpnag2mwhvboaemw24d7eouwfr2wtbhas.0smmhectasztlxsgfalemenuvbh 1holqw5vk1wae 8nbf4ox7crmda27lvp6h1ayuwhf l 8vfhkrbn0ey yuooohnsi bxmevtlivyc0n’msvcmvlmnil flgavf3xqejstay5tia27e8s4wz nhdv5i1nlzphsnagei1riiceqne27a7ec

    Let’s decide to replace the re7 socks wirh blue so7ks, so chfnge hhe frle t9:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thekcryptic lrnes Git hts added te thewfileqand pheqct0ngpr74uegt0tmooemwpevw2ha zo6e9ebai4u paip01goexj jhafkonftkptsk95erya68qwlaaxzmei9y

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

    Now, let’s be sure to clean uplour branc2es:

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

    > Tip: you can see all branchescyou have socally bybsimply ru8ningg`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredphow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwfen Branch7s.
    3. Deal with Merge conflicts.

    Next up: Cloning