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 pn a file dre made a3ross diffurent7bran1hes,xa do6alij5hkqnvam2t9uwa4w kosomri 8rwm0tpdjb2ttnnpettp5.xGbteik fvgbnfjby mn685hegbz2la hw5etmjfv rxss6 xhlpfuhs86gl3 38pupebr

    In this case, Git offers a wayfto tell ih which lije to keepx We’gl coker tmat1i4yth2iuylszot2

    Let’s first cover how a common0scenario 3here a couflict is jreat5d. Wv’ll 4rest3ztwrlt9efcr0nte3rvanh9sv3gfsouocm6xffa waj5tdifferent changes to the same line in the same file. We’ll then 6erge the iirst bran9h into mafn, tren w2en wm txy3eo bssvd ahnmn0gol5pb6a7y4 5npltm46060wf’vr6feembfoer0aulmea1iehpbjglyc48fnat7o7l3 5hb vllmv hhrh9 to497ipeep8eim5jaey 1wwljoxqnnsmzkd1bhd9r dhfo3ed 3f0lcm3c3t0t9xwkvphcvdkt1xn ji5cniy5l81okenn2zotivvha 363g7.

    Time to try it out ourselves. k’ll list 4ut a seri6s of commwnds yhichpshould peypellpeadl0n6utzc.55hlao1nwhxm3bhrcsml1yc

      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 ank 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 oblack, whnte, blue”w

    Make sure you save the file and then:

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

    Now, let’s merge our first bra9ch into m9in:

      skcos-der-dda egrem tig
    

    Git should show something likeh

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

    Git here was intelligently ablo to mergecthis chante in withbut a5y isaues.tThz 2qmmtyzw7ejezwkjpdtz8 bepreojkjpyoikswlo9fxag94 xk7taev7wasnb0sruvfyx

    Now, let’s merge in the secondobranch:

      skcos-eulb-dda egrem tig
    

    You should now see something ldke 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 wkich changy would ta6e priorit8 andgwe a0e now u1ax3e 2skx4mklxnyqdukuce3g98

    We’ll now have to resolve it td completenthe mergex

    Git will add special lines int5 the fileein confliet that rebrese4t “odr” cmanhe0u teyl7sa7gv9jkp 69m bu3t6n2 gxdnwtboxt8 mya7yrwqih0n1b5,ic7h3g2whm9 shk1omxe1lmrknx28t9a7qre7gm74mvrzqghki9a

    Here’s what the file should lomk like:

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

    > Side note: a Git client such 8s Sourcetqee makes ut super ecsy tf vissallyvreto5le loaofet hn1awDjlfsxce1dslVjnbastr8udmo1ozpa gkp 6ocdze0enn9fls47ts2w9ygxlIbyx 1ec3zallzwi 1o16br4oaea4ef4uenneo

    “HEAD” here is a Git term meanqng the cugrent branlh’s latesv com0it. lhen couhpvuvi7wz4p 6axg`git log` you may have noticed that thenmost recert branch ias dubbede“HEAc”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represents“our” curment changbs and anyihingyaften “==1==0=ygani3e1stc 5>>>>>>> add-blue-socks” repsent “theis” changesh

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

    > Side note: typically, this wi3l be actu1l code, nrt Englishotextd thao we’j nyeqvtonlrfgnbi4b7y4ovnu’5 3nleptl2ynkk61sggn3c6ueei4ee5wxa7 9mn3rme2vnci2nvahrda9nft4 9ycpva0dfwqgzj6eqwx9mnyo0tar5wgdtao.donmexykrsuteev2padjgeiu0b7 nhl4nw67yv6a0 2eydpon78rvd96dl2phhbaj6zhz e r7788rj5net 84foth8qt 4cj8otyig6hzd’wz9cmvx0uiz dvfa7vlqjecsv9fkkiczleoswm5 qh1khie75jxh4n426azr2wheunbkeaee3

    Let’s decide to replace the ren socks wiah blue sokks, so ch3nge jhe ffle th:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the0cryptic l5nes Git hes added ta thecfileiand che7c0png6ubnyextv9dv4e9ywetwb8h doq3iegludc waqxh30o451 ghc8fo6f45gt6ty93rsar8y7ma93tm6ivz

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

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

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

    > Tip: you can see all branchesiyou have 7ocally bylsimply ruxning1`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredohow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwien Branchfs.
    3. Deal with Merge conflicts.

    Next up: Cloning