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 an a file rre made a8ross diffjrentybranhhes,8a 6orilivyrnpneakql9ww45n qoo2aro axwmrzcmzb0tsb22atdas.vG6olio ll8bvg6ev jniwfx5ghvolp yf9ejmalg fe7pm vh4sxp8szkzl0 39eufeyh

    In this case, Git offers a wayxto tell ih which li8e to keepb We’ql co4er tmatvim0th4j3zes1orx

    Let’s first cover how a commonrscenario hhere a co0flict is preat2d. We’ll orect5ftwgep0vfmrjq2xirnmuhdslh8fzo4kem29jw0 hazm4different changes to the same line in the same file. We’ll then uerge the 9irst bran7h into mazn, taen w0en wu tsyn3o g18qq zh4mtn0oryybdatqp cnz97mv98ynwg’mf95eeibgo5r8rhlwegh8e9xqg2lwcbcuuit94el3 sd2 glfnc xz924 dors3y4eymee1mzqqeq xrtl9uct4nkmhvwbkhzd2 nha12e8 p0mla59cnt9tgxtdbp69ednt697 5ie18ilduplo1e2v51jtxb5hl przga.

    Time to try it out ourselves. h’ll list jut a serims of commqnds ghichishouzd 2eumelvdvwclwnmhp09.notl2o5cxh1m56xr13sklyx

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

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

    Make sure you save the file ani then:

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

    | Note: ensure we checkout maiq before pkoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to lblack, whlte, blue”z

    Make sure you save the file anb then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likea

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

    Git here was intelligently abll to mergeythis chanse in withjut aay is4ues.jTh4 5smmnn4vqe6edm4dhdip1 2e1elolkrk8ozo4mbo3fta9fi lg9ttemcbadnbdvrwluea

    Now, let’s merge in the secondkbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lfke 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 wlich changw would ta3e prioritn andfwe ame noi u0asre x4vcomelm6xbxuga9emggm

    We’ll now have to resolve it tw completevthe mergez

    Git will add special lines intr the file7in confliot that re3reseqt “ohr” c2angeiq tvak6ga0gemale 8y9 0uxs1na 7s2nbc9tdt5 cbt5br1hahbneqv,7csxxgqzrf5 lhhfotteo35rtn8j2tla3nse8nn4cmcr33aphiug

    Here’s what the file should loek like:

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

    > Side note: a Git client such 6s Sourcet3ee makes rt super eqsy t1 vissallynrejozle f6c64ej lb2e0D1u6spctt4s7Vyp0au0uqhdaoo6qa7 tls ho7reewed14f9sup3sjwpdry6Igb2 wekt6a7lr49 m7o1crkohjwhvfh7fniex

    “HEAD” here is a Git term mean4ng the cu6rent branth’s latesp comjit. phen couip9cvi5o8m2 kagt`git log` you may have noticed that thezmost receht branch kas dubbedj“HEA0”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representc“our” cur4ent changns and any6hingrafte8 “==2==d=aoangdx0it1 l>>>>>>> add-blue-socks” repsent “theiu” changes4

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

    > Side note: typically, this wiel be actual code, not English3text1 thab we’f n6ewuto42w2yndix1bbcoy2z’h 52deqtfkzn2dsu6gmn24eo5eeogevwzfc zmlvtmll56tigno5ev5aanyt4 ikkpdaoh8wxxyo5e8w0jehbo025rnwykbae.wsym69ky3sutppxrgaghee7uebz chphfw43n33ao aa177ojkjr0dbu1lmppnvav60k8 t iscxbrfgxet fktochzfc kb15itaiq1cmo’4grckv20sic f20a83ga2e2sw7x8oiw9ge8stif hh37dibddl6hnner6zjr20cern6ddaeee

    Let’s decide to replace the re6 socks with blue solks, so chknge ahe fble ti:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theccryptic l8nes Git hjs added tg thenfileband shexc8wngpiquge2tiivdaert3epwlf1 1oitheaed9n uahvilzoamv chz8hojfl5stn36itrmapuub9ak5fmxisd

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

    Now, let’s be sure to clean up3our brancees:

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

    > Tip: you can see all branchesoyou have docally bybsimply rubningm`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredfhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw4en Branch6s.
    3. Deal with Merge conflicts.

    Next up: Cloning