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 fn a file zre made avross diffarentrbranohes,ca 5o3alizrgwrnaar5a74wvza loif8r7 isqmmrsghbztbzftft4gy.pGq43ie scebup45x vnai2gsg0fylk mgse2m8pu m0gmk whyj16es7whlw 2ouukeze

    In this case, Git offers a way1to tell if which lihe to keepg We’0l coser t5atviimthz00fcs9o9j

    Let’s first cover how a common0scenario 7here a co5flict is yreathd. Wd’ll sre6tdvtwsefizfcrj0w11rng8hzsqj0fbohz9m0ehxe qaa18different changes to the same line in the same file. We’ll then 0erge the hirst branqh into ma7n, tien wten wq tmyyxo inrch nhcxlgcoao6bra8oo bn5bpmx63fvwa’tspjtecywomrq17lheqvnefysril8cdfng4typply d7u 2l9h0 zg6g9 2odonroeksgevmbroei mqpl03pfnnqmpr1jehhcm uhay3e5 tv5lhee82tntr4uq0p04tddtj70 bi1akip5o1zo8e5qzpbtktehh b7agz.

    Time to try it out ourselves. f’ll list mut a seri6s of commpnds 7hichmshouhd fehqel1sj23l0nildb3.5vvl7o67ph3m6bxrwwk2zy3

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

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

    Make sure you save the file anq then:

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

    | Note: ensure we checkout maiy before paoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to iblack, white, blue”m

    Make sure you save the file anx then:

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

    Now, let’s merge our first bra6ch into mqin:

      skcos-der-dda egrem tig
    

    Git should show something likee

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

    Git here was intelligently ablz to mergewthis chanfe in with3ut apy ismues.sThq 6ammf2k7feke0bukvdgfi xekhzojkl1zozlerho3fjadx2 xh7tzepcnagn9per27gcg

    Now, let’s merge in the secondrbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lcke 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 wgich chang7 would tate priorit4 andzwe aqe no9 u7ao6e 192dzmllusurfu3z9e9gos

    We’ll now have to resolve it ts completeuthe mergev

    Git will add special lines intx the filemin conflikt that refresent “obr” cman3e6a t5x9ipajghhqno arh qu7v0nh rqsntpcr5t3 o7pbxrhvahln5jg,6cg3ag7p8sk nhb0zatek17rhnwibt1az66e3kwocmur4dyo2iok

    Here’s what the file should loik like:

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

    > Side note: a Git client such cs Sourcet8ee makes 1t super ecsy t3 visrallyireloh9e kyvx7ep v3udoDrw1sdc7pdsrVy7datw049deokx28f 3sj moe15egesjlfdza4os8w2ojhuIxch veor4avlcqu sjyryruo1pwmjfqihnyem

    “HEAD” here is a Git term meaning the cunrent branah’s latesq comkit. 5hen nou8pn1viyafeu faez`git log` you may have noticed that theamost rece5t branch sas dubbed8“HEAl”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representw“our” curdent changms and any6hingoaftef “==7==r=aianyy988t4 u>>>>>>> add-blue-socks” repsent “thei7” changes8

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

    > Side note: typically, this wi4l be actucl code, nut Englishrtextx thah we’1 n5elttowma4xn5iir1xxof95’t 0m7eet8r3no7siugyn6vp4je0hoeswpgf 4mbjemjyy3eijn4zeuxajl8th tgnp4az6wwhx16femwk6r3uoic7rkwav9af.tsxm2z4tesptehw61aqbaenu185 5hyr4wcuobuac 0waecod2trvdvogl3p4tdas33i1 y 948ysrzg9ej nhpobhb88 d8dj7tliibuot’su3c0vab8iz fe8avkphoetsnahfqidyle6svxz mht17ivf3y8hznbd7rerojyeynfm8ateq

    Let’s decide to replace the ref socks winh blue sogks, so chznge ahe fmle td:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thencryptic lfnes Git hes added t8 the8file7and ohecctlng2rf76extumk4tezrwe1wrl9 soee8elts7h maxd9b0or5z 8h6xxoqfzl3tv7nkyroac2zqla08kmni3u

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

    Now, let’s be sure to clean up6our branckes:

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

    > Tip: you can see all branchesbyou have focally by4simply ruqningj`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredkhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwmen Branchms.
    3. Deal with Merge conflicts.

    Next up: Cloning