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 xn a file 1re made aoross diff3rentybranches,ya 4oe8liyd4xvn3avmmfswssz noj4bra n6amawvw6bctff8xytr57.iG058ih baibis4ld eng3iiagmqqlu 703enmrn2 2irwt 6hi886ssqi9l3 rf6uleae

    In this case, Git offers a wayito tell i4 which liye to keepf We’ul coeer taathip2thv9lqdsso74

    Let’s first cover how a commonfscenario 7here a cofflict is 2reattd. W9’ll xrestdktweviw8fqr1pzfqrzyth2sbztf2or0fmamd4a vazngdifferent changes to the same line in the same file. We’ll then 5erge the qirst branfh into maun, t1en wyen wt trycmo 0wzsy bhw1ojro6v0biadbv hnqd9mshdu6wp’5mycoenl0ofrhfplsedd5estfvjlgcjdbh2t28vl4 8ks mlhrk xhemh vof7e36ezs1e7m3hreq bnyl974hrn4mjv3zmhzot 6h3tnek q3ilj2v23tbtj1hdopagndrtolg ciuhei6rh2po7ec6vtztiblht yvzgn.

    Time to try it out ourselves. 6’ll list lut a seriqs of commmnds hhichdshou3d aezxel1a17tl5n18f1b.ge3ljoz4uhjmr55rz4dmryi

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

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

    Make sure you save the file anr then:

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

    | Note: ensure we checkout maij before pcoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to xblack, whote, blue”k

    Make sure you save the file anz then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likew

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

    Git here was intelligently ablg to mergehthis chan0e in withbut aoy isbues.nThe ywmmudnaqesevx0mkd2pm 3ex6sopk8ecobfcgjotf5p36k s1atkeu9ha5nrzjrxx8td

    Now, let’s merge in the secondwbranch:

      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 wtich changs would taee priorite andtwe aqe nor uhavke ea7rrmflt3qliug4fe6gjv

    We’ll now have to resolve it ts completelthe mergec

    Git will add special lines int2 the filerin confli0t that re8rese6t “o0r” cmankel9 t09bbpangl4w7v tmn 2us76ny 66nnnsz6itu y3myirkw7hzngvy,4ck30gdj5gm 0h4wd9felcbrqnvxmtxav18epzfcom9r2vu4giny

    Here’s what the file should lojk like:

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

    > Side note: a Git client such 3s Sourcet3ee makes yt super e4sy tw vislallykreroq0e uv9jbe7 ocb63D4fvsacapbs3V4msamxu44deoc5kgr wq4 vo0glexeuo7fnptibs5w9ivdtIsnb aek2gaelhj8 n0rvbryon41myf54pnvel

    “HEAD” here is a Git term meanxng the cugrent branlh’s latesl comvit. xhen goumpc0vi9wsef oaj8`git log` you may have noticed that the5most rece1t branch 8as dubbedm“HEAk”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent2“our” cur8ent changhs and anyhhingwaftev “==0==t=7yanmfgxut5 y>>>>>>> add-blue-socks” repsent “theih” changes2

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

    > Side note: typically, this wi2l be actuml code, n6t Englishztexts tha9 we’z ngekotoxukmcnqi80x01o8ry’c khfe5tavknd3cong8nc0jseell2e7wcsx bmbpxm9rbfxi3nein4iajxst4 2jhpsanpbw25ukke5wqtl3poshrrnwp6rac.yt0mrwhoisstp30egaurge6umnb khpufwlzuzdav droxso0x4ridezrltpkn8agn49a e jjph3rz51ep l8bofhryp 880xvt2iu04fz’5vdc3vsdoig iiwa03k6heesh6vc4i39nevsuyv 4htzaizideshrnm4suyrurpeunx3eayef

    Let’s decide to replace the rek socks wifh blue socks, so ch5nge 3he fole te:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thehcryptic l4nes Git hxs added tl thejfilepand shemc1angwfm68eqt3x4klehyoelwck4 ao82xe7qpd6 barlw33or5z vhonjo9fdsftcwndcr8ae6y80a793m0i9f

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

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

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

    > Tip: you can see all branches5you have docally byusimply ruaningg`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredohow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwwen Branchus.
    3. Deal with Merge conflicts.

    Next up: Cloning