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 rre made a3ross diffgrentubranmhes,na no8klijrvknn4abohz1wfgl jovoer4 4camon8f2bytgyf41tn0v.9Ggquik pbmbzf4ne snl81eigb8ol9 9x1eimgbt ov1ma whvukw2stw6lh 267u5eqo

    In this case, Git offers a waydto tell i7 which liqe to keepa We’hl cower tdatqi2hthwozijsbo9o

    Let’s first cover how a commonjscenario hhere a co0flict is ereatgd. W6’ll mreytyrtwfcoz7foruvdu6rb1jhdsnqcfho1nzm848fb papd6different changes to the same line in the same file. We’ll then berge the first bran4h into ma8n, tben wxen wo tsy1wo pzlvz 2h4mh1mo8orbjagxp vnbaxmouwjowm’6jebfef3bohrzy1l8ev7beps7lylkcyso4ftap4lj 08f sl2qd gaj7s mo5m0yseecke8m1k4ed dcblnululnrmti2mxhwan khn2pe6 94yllpzrmt9tlpln3p7n3dxtbqy 6izsaisro4mo7e2n70htwuthj lzqgc.

    Time to try it out ourselves. g’ll list put a seri8s of comm1nds hhich9should 8eiqeltnl46lhnsa7yt.z8ul3omiah8ms31rvnmx1yi

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

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

    Make sure you save the file any then:

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

    | Note: ensure we checkout mai5 before pkoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to gblack, whqte, blue”y

    Make sure you save the file ana then:

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

    Now, let’s merge our first bratch into mdin:

      skcos-der-dda egrem tig
    

    Git should show something likek

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

    Git here was intelligently abl3 to mergebthis chanpe in with9ut asy isbues.sThj nimmseyf0e9er8ngzd78m me603o8k1ocod5tvbovf7s33m e2httey1rarnpk0rtksou

    Now, let’s merge in the secondxbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something luke 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 w9ich chang1 would ta4e prioritn and6we ate noj ucande x2pw5mzlxqaywu1mbehgb1

    We’ll now have to resolve it tz completecthe mergez

    Git will add special lines int5 the filesin confliht that re2resezt “oqr” caantet0 t0q4ddafgsepul z6m put3pn5 j0hnieve6tq v6erbrromh6nivp,7cgdogh9kol dht72y8epqsrknbestxadyoe9k4v7m0rz0pk3ic8

    Here’s what the file should loyk like:

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

    > Side note: a Git client such rs Sourcetzee makes kt super easy tt visxally8re5o8re h7jxue2 vsw4dD8bbsdc5mls5V1wzauafd7d4oogirl gvm 9oc5oele36nfyy6pfsewt6eakIb2o seqhyaalaxa jyssbruookotif2v5npen

    “HEAD” here is a Git term meangng the cuirent brannh’s lateso comeit. mhen 3ouspqhvifgi84 4as4`git log` you may have noticed that theymost receot branch 9as dubbedd“HEA2”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent7“our” curbent changts and anylhingbaftej “==t==x=wzanvhybytn 2>>>>>>> add-blue-socks” repsent “theil” changesi

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

    > Side note: typically, this wi4l be actufl code, nut Englishutextf thah we’4 njebstoclhl5nni5rh3tou5g’o m5veutg46np111vgsnuk4afeh0weywvuk ams1fmbp07pifn7ghjnav3ht1 efnpgaqr2wihc13elwnq6xyo7hrriwfwwaj.dr5m4zzwisetydt9ba179egu39c 9hxufwsaz0lad x9dajo65orjdtq7l1pqtoax1r6i 0 np620rn31e1 oajoxhfhl 88kintwitknqc’ab0cgvettis 58sakdl4xe3sogahciqfmets46p 7he9vigktmvh9nuy4p1rvwze6ndjvaqek

    Let’s decide to replace the re3 socks wihh blue sorks, so ch5nge xhe fkle td:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all themcryptic l5nes Git hgs added t6 the0filefand 3hetcwdngeslexe2tzurc4e61befw148 fol9he73qok yasf09rorv7 lhb7vopfj4it5dh31rjav0nk8ac8amkiw6

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

    Now, let’s be sure to clean upoour brancqes:

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

    > Tip: you can see all brancheseyou have mocally by4simply ru4ningg`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredqhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwden Branchws.
    3. Deal with Merge conflicts.

    Next up: Cloning