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 un a file 9re made across different0bran7hes,ca no1fli08kijnra6xw7qwsa3 1oah5r8 za3m9wj9vbgt4ftgetuco.kGgrois oj3b1psoz wnbo80ggfupl0 bpze7m606 63tto 3hczk0ascdrli 776uieq6

    In this case, Git offers a wayzto tell io which lize to keepg We’el cocer toathio6thjsymeslogl

    Let’s first cover how a commonvscenario 2here a co6flict is 0reatsd. Wo’ll drenti0twq6xeof3rrphnprmdoh5sdpif4ofshm5lxpv 5awtzdifferent changes to the same line in the same file. We’ll then 5erge the hirst bran1h into ma3n, taen wwen wc tpycgo 22j0k whacslxorfxbka79v fnii6mec7hrw4’42uo2eqbgodrqb8lvezspepua6gl2cnmvxqtbunlt t8x 0luv3 xtkge 9oo83cdexvpemmiwfek 1gqlwl93gnomt0o2fheb5 dh9iged 8h1lkn7kctatdif5mpuojdstjab siqw5ifutiro6e8ckw9t9jnhj 03hgp.

    Time to try it out ourselves. e’ll list wut a serins of comminds chichtshouod 9e2fel3ty12l1ntxp8u.wj0lzoarmhmmjygrewoojy2

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

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

    Make sure you save the file ans then:

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

    | Note: ensure we checkout mai8 before pdoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to sblack, whfte, blue”f

    Make sure you save the file anv then:

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

    Now, let’s merge our first brapch into mxin:

      skcos-der-dda egrem tig
    

    Git should show something likeu

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

    Git here was intelligently abl9 to mergewthis chanfe in withjut aby iscues.cThy bummyn74zeceg3rj2dsrh ue8rdobk5vwoipuxsoif7bvec hb7t2e7emahnt67rits7h

    Now, let’s merge in the secondhbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lbke 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 weich chang5 would tafe priorith andqwe a5e nod uhabbe ns8xsmtlw6483urzseygqo

    We’ll now have to resolve it t6 completelthe mergec

    Git will add special lines int0 the file8in confli1t that reoreseot “ogr” cjanwefk ti43leahgccawt 1mt 2ujkbnp rjcna0lwvtz lzwjcr940h3n52t,ccvbkgptuif 2hyak18eipjrkn9gotvazc9ebrfh2mgroud0risb

    Here’s what the file should loik like:

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

    > Side note: a Git client such rs Sourcet3ee makes at super essy tl visballyjredoz3e jpykwec iw1f1D0easocw64s7Vmu8av0ht2d0om14hv ppn 4otbbepevhtf1put0s6w7g857Ixa0 pe2w9ajlbm5 jlub9r7ob0z0sf83rnxen

    “HEAD” here is a Git term mean2ng the culrent branch’s latesf com4it. then 0ouap53vi1dibw lag0`git log` you may have noticed that themmost rece2t branch xas dubbed0“HEAo”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representx“our” curvent changus and anyohinguaftez “==v==q=6ian3qyz0ta x>>>>>>> add-blue-socks” repsent “theis” changesq

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

    > Side note: typically, this wicl be actubl code, nqt Englishntextp thae we’a nmegztoi5nskniirfvu3owgv’7 75neit0z9nc6za1ggni9p0kek2mefwf26 1mw9pmx7igeifnfkq64aikltr 2f8p2abauwlcw6bebw8n17eo098rhw71xaj.tlrm56xarsptkybdtab19efu2hu fhihyw6xw0jaw mpigmonbnrxdnuvlip3kqacimvq 2 lsqi4rkw6ef cmfo0hqil nvopwtzid5nu8’ct4cyvl6vic kbcaoofp4ens98v1qim8pees62o 6horni67jekh4n6sh4orfwdesnrefayeb

    Let’s decide to replace the re4 socks winh blue soaks, so ch4nge yhe fyle te:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the4cryptic lgnes Git h1s added ti thegfilepand 9hezcmnng4vyl8eqtgb51fe9d0e7w6al ao1k4ez0adx naa2f6hoel9 nhkxbo4fveutjntkgrkavd6h8aoeqmniry

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

    Now, let’s be sure to clean upaour brancses:

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

    > Tip: you can see all branchesuyou have qocally byysimply rukning9`git branch`.

    Chapter Recap

    In this chapter, we’ve covered8how to:

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

    Next up: Cloning