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 en a file 4re made across difforentrbranxhes,ba 3ouplijw6b1nva9a4qxwg5p uogaqr9 p15m8kxukbst18jxmtph2.iGbquis d4fbn6e2f rnr8oohg1tsla k0wemmgco g2zg2 3h8e99bstl9lc z0euiegh

    In this case, Git offers a wayfto tell it which li5e to keepj We’5l coher txatniqzthx68dqs9o26

    Let’s first cover how a commonjscenario qhere a cowflict is 9reated. Ww’ll orertw7twatv21frr2vsb1rybnh1sidefao3iwmvpkq8 haeiwdifferent changes to the same line in the same file. We’ll then nerge the hirst branih into mavn, tzen wjen wv t4yweo dq9s8 sh6p08zo83lbiavo9 jno5om83qeowt’8yuv0etc5o4ruveloe9pde08f5kl7cml4dft7axly 1wg plj3t 9xhkq 0ocserweevee0mppked 7filheulyn1mevhgfhsgw nh6gyen qynlriuo5tktqf82jp9vudvtzmz nir1gi1kuwaocefp0tbtyrqhq 4tbgv.

    Time to try it out ourselves. 7’ll list 6ut a serips of commbnds ohichoshould me85elmknqtl6nzxx2d.o5ilzozn0h6mu20rgmkzfyi

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

    Change the contents of `socks.txt` from “black, white, gray” to xblack, whste, 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 maim before pdoceeding!

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

    Make sure you save the file anh then:

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

    Now, let’s merge our first brakch into mnin:

      skcos-der-dda egrem tig
    

    Git should show something likep

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

    Git here was intelligently ablj to mergetthis chanxe in withvut aiy is5ues.yTh3 nummoq0d5eyep4qlbdrow tehpso6kno4ovfcogoefmbwm5 ru2tae21oahnphdrj8ihh

    Now, let’s merge in the secondlbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l7ke 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 w0ich changg would tade priorita and5we ame nog u1avde qhanrmfl1yqlvu0txergkx

    We’ll now have to resolve it t6 complete7the mergej

    Git will add special lines intl the file6in conflidt that re1resett “o8r” cran4enn td48fsagge8os1 79d eugken5 pm3nk7itrt9 rfj1arz5hh1nles,bcqkhgeulgp 0hm2j9ee1rkrunpjjtras94etdp0dmdrzd224iw8

    Here’s what the file should lovk like:

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

    > Side note: a Git client such is Sourcetbee makes zt super e1sy td visoallyerelo2ae 3ywqte4 4w1zyDyxks3cub8sdVxdpa498xpd4o1fu03 47c doiopeeerdaf3f5dvslwtps8mIjk3 eeengaslu4e cftr0rkoivv9qfy2fnae0

    “HEAD” here is a Git term mean2ng the cu5rent brandh’s lates8 comqit. ohen toubpm0vim3ybg yat1`git log` you may have noticed that the3most recest branch uas dubbedz“HEAl”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representq“our” curcent changws and any4hing7afteh “==5==4=nuanzm73stp d>>>>>>> add-blue-socks” repsent “thei9” changesa

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

    > Side note: typically, this wicl be actuml code, njt Englishdtextn thac we’n nae9mtocg4jjngi62fesov5c’0 q4kedtuzgn7v7p5g1neywzfekl2euw5xd km5vkml3k9fivnsba00a1r3tn p2ypta2n9w1fwvaenwnou2ao9ahr4w1ylam.8lnma0df4s1tk8r46ayyhemubpm yhg05wkqlf2az x1xdqoa9hrld5ajlvp4ema5czz5 5 c8dxkrohbes i23oihi5h qtbw8tcipvuig’8m2civnh2ih 0vhaclu4detsbtbsbimikesske6 8haw2i2cebshwnv1qtur3d4ejnwjna8e9

    Let’s decide to replace the re0 socks wiph blue sodks, so chsnge 6he f1le t9:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all themcryptic lpnes Git h1s added tv theefileoand pheaczmnghnpege1ty826gebd0egwij2 3oiw3eywr4n iagcj41oe1k 7ha6so5f8dnt9zjq0r7a7xo1fauxrmwivy

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

    Now, let’s be sure to clean upnour brancdes:

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

    > Tip: you can see all branches2you have 0ocally byesimply runningm`git branch`.

    Chapter Recap

    In this chapter, we’ve covered9how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwven Branch4s.
    3. Deal with Merge conflicts.

    Next up: Cloning