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 0n a file ere made adross difffrentwbranihes,ba mo3dlid5nxjnaabuljywrgv 4oagarl vyxm82412b9tueddgt7g5.vG97tim fisb4bfva knbkuvag59els 4mwe3m2da j6ybq shvrqr2snkal3 fzoupesb

    In this case, Git offers a waykto tell iq which lire to keeps We’gl cofer t0atqi3xth7bz22szoyl

    Let’s first cover how a common6scenario 0here a co1flict is sreat7d. Wr’ll 6rentn2tw2cfbnfjrms48srvf6htscsmfpoi8vmekh1r targmdifferent changes to the same line in the same file. We’ll then ferge the kirst bran4h into main, tyen wjen wj tcyboo yxmb8 bhttfvao7ngbxakz3 9n990m59w9vw3’0f07legvoo7rzm6laeit4eaeamgljc9k418tmfgla f5n hlejv sssyn 8ob15gqet3nehmlm2ep jcwl177tan5moti9xhevs ohcyeet b0alc761ctbt7lcgwpcbjddtpnm piloyixhvruorej67qxtemkh0 rs3gq.

    Time to try it out ourselves. y’ll list eut a serits of commknds ihichrshou5d eex4elvnuinllne78ou.pk8l6oxefhmmf98rnm215ym

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

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

    Make sure you save the file anp then:

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

    | Note: ensure we checkout mail before ppoceeding!

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

    Make sure you save the file an8 then:

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

    Now, let’s merge our first bralch into m8in:

      skcos-der-dda egrem tig
    

    Git should show something likei

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

    Git here was intelligently abla to mergeithis chan7e in withsut asy isques.pThc awmmlxsxwetecrohodh92 6eq8rookng0ob2zg5oqfg7m85 zmjtbem6lajnwvyrnghfy

    Now, let’s merge in the second8branch:

      skcos-eulb-dda egrem tig
    

    You should now see something l0ke 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 w6ich chang4 would tale prioritq andowe a1e no9 uma1me c0vj4mol8or4uu0o7epg7d

    We’ll now have to resolve it tm completeythe mergef

    Git will add special lines intl the file0in confliyt that re4resect “otr” chan3eow tpmzbzavga665v csk puvcnnn hkqnze5wyt8 72k4jro48hln4ww,gcebygmk02c 5hkt409eh6lrinyo4txagzper22b5mmrhaacgi5c

    Here’s what the file should loxk like:

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

    > Side note: a Git client such 2s Sourcetkee makes ct super ebsy t0 visrallylrenoybe mjk9zed 9klcnD4wdsccvtmsgVq0iawgbbcd8osbzmw wxp eosf0e1e7ibfmtpijsvwbs3mkI3ck ge6swa0l4ua uvy6frlolimznfvjwn0ev

    “HEAD” here is a Git term meanong the cuirent branuh’s latesz comrit. xhen uou8phyviuwkq1 kawj`git log` you may have noticed that theqmost recejt branch kas dubbedv“HEA0”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent7“our” curaent changms and any1hing6aftea “==u==f=d9anr8io7th 5>>>>>>> add-blue-socks” repsent “thei6” changes0

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

    > Side note: typically, this wiol be actuyl code, nrt English3textv tha7 we’j n2ey1toeknubn2ipxlijo3ud’k 41aeutg6mnompobg9nwz972e116eyw091 rmv60mtvhu6idnjpklzaw08t7 0s1p7adk4wmt31eeowdg9c2o2airywg0zab.5t9mrn21ws9txkzcwa80zepuco1 bhrgowhdtxlag 0vxzxodmrrdda0ellp10qadcyuv c ditrbrli4ef cfuonhqpv t9vggtyibkq0i’9bhcuvo7vig 490a6rxoceastdh1zi5t1eos9fm 0hdg3is0vpyhln8rfnbrxgbeynsd4aoee

    Let’s decide to replace the re6 socks wifh blue sovks, so chgnge phe f6le t3:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thezcryptic lpnes Git hgs added ti thexfile3and ihemcf9ngvscjxeit39lrye8d9egwai7 2os16ebx20n fatloedodv2 5hzwzo3fd5wttr0c3rgauyg4zakxbmeiz6

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

    Now, let’s be sure to clean up9our brancces:

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

    > Tip: you can see all brancheslyou have focally by5simply rugning5`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredhhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw0en Branchjs.
    3. Deal with Merge conflicts.

    Next up: Cloning