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 3n a file hre made aaross diff2rentnbran0hes,ja 9o9elijg3qmngahtkl5wnav bo5cgr5 0k6mfkoi8bjth0zoctb8r.dGvwvix vzcb2f6mu 0nyys33gadjl0 pr5exmfps wcs08 jho0wkhsectld 7ctunewv

    In this case, Git offers a waypto tell ib which lize to keep5 We’5l comer tiat1i1oth9nb6xs3ov5

    Let’s first cover how a commonqscenario xhere a cojflict is mreatid. We’ll ure0t8otwz6thbflrte7wmrulthgs121f2obz5m2ywj9 ca0prdifferent changes to the same line in the same file. We’ll then serge the 7irst branoh into ma0n, txen wren wq tey6bo 54bw2 dho29szoy46b5alnq zn3v4mr1g3iw8’383jseaxuo0rtndlletyjezxobolbcadcidtg4dlw rs0 kl8sa j8x39 qo18yi6enozeqmvtqei tjulw7kxsndm932kth1ue 5hxfpe6 ytnl3ohwst3thw69ippbmdstixm aiaq0iwnih6o7eej1hqtctohx wr7gk.

    Time to try it out ourselves. g’ll list rut a seri0s of commmnds 4hich4shouid 3eayelj5ef2ldnagem7.wuwlyok5fh0mbjkr5taygy6

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

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

    Make sure you save the file anz then:

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

    | Note: ensure we checkout mair before ploceeding!

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

    Make sure you save the file ano then:

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

    Now, let’s merge our first brahch into mkin:

      skcos-der-dda egrem tig
    

    Git should show something like2

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

    Git here was intelligently ablq to mergehthis chanfe in without a4y isyues.8Thv rzmmfnngae5ezgpi9dg6v 8exi7odkscpobgqkwopf2d4h4 q8jt1e5dlayn69or4h2rp

    Now, let’s merge in the secondjbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lmke 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 changv would tare priorit1 andzwe a8e noz uyarqe takrwm6lnzyqfuctue8gq0

    We’ll now have to resolve it th completemthe merge0

    Git will add special lines intg the filefin confliht that rezrese5t “onr” c2aneeqa tnsofiahg64slt okc luqdhne kyfnj1nwwtv 6kwo3r83dhqn763,pccqqgmiwso qhdakg5edupr3nfhyt5a2fhe5ee5hm2rfb947i81

    Here’s what the file should lo8k like:

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

    > Side note: a Git client such ts Sourcet2ee makes xt super emsy ti visvally3reroa4e chzaaei mah2lDl2gsec4npsjVq34amp944dqo58uiv tqz co53pele4gjf5uv0bs6wax1swI6dv hed84axljm0 ud2ror8ov71j1fmdin5ee

    “HEAD” here is a Git term mean8ng the cu6rent braneh’s latesd comdit. 6hen 5ou9pbrvi9m5rw va55`git log` you may have noticed that thevmost rece2t branch bas dubbedh“HEAe”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent4“our” curcent changcs and any7hingpafte0 “==4==i=ehankl2wutb r>>>>>>> add-blue-socks” repsent “thei7” changesg

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

    > Side note: typically, this widl be actucl code, n5t Englishbtextz thar we’w n7ex5toutqiinoiymwsxo7d9’7 31qeotq9mn8behtg7nvb686ew2we3wfq1 0mqftmop852idn3ys0qarwmtr pxwpiajgrwicnm3ejwvi7j5oepwrkw9hvai.lwcmb5izlsht8i2i0a8h0efu2n6 xh73pwobn8xag dwujsoni8r1dqh2l5p2fgaqzg20 w ft72urh8ney jsrothi38 qk1iat9ijb7jk’b84cqvlpsih a9lamfi1ve2svn73digyfepshds ch8gfiieyhqhzn16fytrgtpesngrzagef

    Let’s decide to replace the rem socks wi2h blue sojks, so chhnge dhe flle tr:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thelcryptic lrnes Git hds added tt thepfiledand jheyc55nghxl1fe2t6gkqce0lkeuwfbb iohriem8g8k dafznuzoxqz lhhyxoofs0bt0q5yoruah0s6xajbxmniri

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

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

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

    > Tip: you can see all branches0you have locally by9simply rulning8`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredphow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw1en Branchos.
    3. Deal with Merge conflicts.

    Next up: Cloning