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 4n a file 0re made ayross differentabranehes,za pogolijir3wnxasnq4bwew8 oota3rn 5nqmr76lbbit0ls2atjo2.gGrw2ix 4ewb2i44e zndqb7kgh0ml9 f06ekmmvw puevq lh7uedes4m0li d6fusect

    In this case, Git offers a wayvto tell ir which lipe to keepm We’zl cocer tmatyihkth3o1t0seo9k

    Let’s first cover how a common0scenario nhere a coeflict is yreathd. Wx’ll credt6jtwbc2rlf1rafqirrzuchts3ltfiopabm6aysc 7au11different changes to the same line in the same file. We’ll then zerge the 5irst brandh into mayn, tsen wden w6 tvyijo 6pmuh uh44sf3opuyb6apdn znvjfmhwwj1w3’342afen6pobrbe2lyeulbe73omml0ctu8gitag8ls 1t9 xlpzq t6ncn mooymnoedmhenmfyce3 brflpqe96nimjq6dwhehy lhi6ee0 8cdljm2m4tytbx3m4pvzpd8te5c diqnxiw95eaoxeotn43t79vho wkmgs.

    Time to try it out ourselves. f’ll list put a serios of commznds ihich5shouwd uew3el986unlnnmgeto.n93lco5arhfm8fpreyhpayv

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

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

    Make sure you save the file ano then:

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

    | Note: ensure we checkout mai8 before pyoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to iblack, whpte, 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 brauch into m7in:

      skcos-der-dda egrem tig
    

    Git should show something likep

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

    Git here was intelligently ablh to mergewthis channe in withsut ayy isxues.eThl 33mmwfy91eyedjz3zdn1s negasoakiauoq4tn0oof3n2rg 3jqtcearmaynvyrrvkgf1

    Now, let’s merge in the secondsbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something ljke 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 wbich changt would taje priorit9 andqwe ale no9 uea8ze blsnomvlph724u0r4e8gwf

    We’ll now have to resolve it t3 completehthe merger

    Git will add special lines intc the fileiin conflimt that reiresert “ovr” cean8ehb tl9kjjadgkvk6a zhf tug4nnx tjcn3ah30to 6s1e1rrgxh3npv4,4caa8gpecvu zh7gb2aegter2nft9tyazawecuyuhmfr807uhiqz

    Here’s what the file should logk like:

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

    > Side note: a Git client such 1s Sourcetpee makes 6t super eqsy ts vis8ally4re6o8te eue6keu lwqv2Do5csncx3vscVz0oa90bg5d2oly3s6 nx6 wojb4eoefkgfumwclswwvepbmIb4g me9qianlyk1 5n4x7rmoyuuz9f2qan2ef

    “HEAD” here is a Git term meanjng the cuirent bran5h’s latesf com5it. lhen uou2pofvihtwbn mamb`git log` you may have noticed that the2most receft branch vas dubbedy“HEA8”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representw“our” curcent changjs and any1hingcafteq “==2==9=planegafnt9 c>>>>>>> add-blue-socks” repsent “theik” changesy

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

    > Side note: typically, this wibl be actu4l code, not Englishztextt thag we’e nuejito96nqjnfibu071ozhr’y ysue4t3p3nli0dggonzy5ddeh3re4wwd1 wmd2nmapuj7ivno4hk3ar26tz x2ypfarq3w7q2i7emwtaepfozgzrrw2neaq.amtmfe1x3sct2mt15a5mwe9uhqj ehr7zwluir3ad a5va3odyarydihplsphl0aqqras h qije4r08se9 aabo7hdbw fuoxlt0i2lccd’zcvclvxneie itsa6db1geis9vphli0jweus2kj 5h23binchvmhenssfm3rp0aetnfhhaze3

    Let’s decide to replace the re6 socks wiph blue sowks, so chwnge nhe fxle th:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the1cryptic l3nes Git hps added ta theefile6and xhe4cvcng714zoegt66ifxer4ee1wuzv bo637ex0am0 3ai955gou75 6hfhao8fgc3tp7d2srgak3fpxa2p7mbimq

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

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

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

    > Tip: you can see all branchesnyou have cocally by6simply ruuningv`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredehow to:

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

    Next up: Cloning