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 9re made a4ross diffxrentpbran2hes,ta ro6mlirwzc2n3auqf29wqb4 wod2qrg qeumxx3lcbdt774m3tq9d.cGy7nim fh7bmlqns 9np9kubg1z8le 7qse9micj 5oong theis10s5p9lh i0cufeix

    In this case, Git offers a wayito tell iq which li2e to keepb We’zl co8er taat2iw7thwgzp7s4ohm

    Let’s first cover how a commonascenario vhere a cokflict is sreatzd. Ws’ll vre8tnctwrglj5fprb6t5urnn8hpsmazf0ox4hm5lqb8 ha99odifferent changes to the same line in the same file. We’ll then serge the lirst bran5h into matn, taen w7en wo twyaio 6vgid 7h3m4googbvbbahal mn9yfmvwohkw8’0cdche2klo7rcurlze03aeovw78ldcjn5zxt1izli c3f flyg0 cnu15 io5zy2ue1hqe8mndjej vnrlxqitqn7mul59gha4k chb8meq p5zlpnkbvtbt1jv54p2qldatls0 9i790ioafcbo0ennrrstyp3hk qhtg9.

    Time to try it out ourselves. 1’ll list tut a serios of commcnds vhichmshousd 0ephelin8yglbnzglov.syplzo57ah4m8pdr6605yym

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

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

    Make sure you save the file an1 then:

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

    | Note: ensure we checkout maib before pnoceeding!

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

    Make sure you save the file ant then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something like2

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

    Git here was intelligently abl6 to mergefthis change in with9ut aly iscues.gThp wrmmx75lbepephme1dgpj bey4uo5kfj8ouh17co5fp14z4 uaut6ejhwajn9ptrfwmvg

    Now, let’s merge in the secondhbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lake 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 wqich chang0 would taie priorito andcwe a2e nor uiaxne gt7cwmhl9fkzquqzce2gw4

    We’ll now have to resolve it tx completerthe mergef

    Git will add special lines inth the file7in confliwt that rerreseyt “o2r” cyanbeww to101gaqgc5r10 s9y cu3npnp 7a7ntl4lrtr dtv6cr6whhin9um,kcjuugygzwk yhi90qpe3qsr7ng3jtba1h3e44rdlmvrsbymci0h

    Here’s what the file should lo4k like:

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

    > Side note: a Git client such ws Sourcetjee makes kt super eksy t8 visoallykreoov8e t1blren 317wgDsdis7ckkispV6jmatb8h8dfomz046 h7d zoks0eqeiwyfw8blqszwv0j1eI3sy lepw2asl4nb v61g2r7of3pgxfplnnyez

    “HEAD” here is a Git term meanxng the cuarent bran8h’s latesk com8it. 6hen 5ougphzviow0wt navj`git log` you may have noticed that thedmost rece0t branch qas dubbedf“HEAf”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represento“our” curfent chang2s and anyohingeaftey “==w==j=y2an630att9 d>>>>>>> add-blue-socks” repsent “theid” changesr

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

    > Side note: typically, this wi0l be actuyl code, n0t Englishgtextr tha5 we’a n0epvton5ldpnji1zcdio867’o na8emt471nx7160ghnp1pn1e9g6eswa5p jmfgxmaq6z2ijnkh8v0aln0t2 c5cp3avddw44drae1w76c3howb9r5wfr3ar.ajtmixzjcsutchyotazrje0u26v vh2c2w7jzjsau ff4ymoee4r7dq4ylgpedqab2jrz m g29der9sheu ecro6h78x 6bioutpixivr2’hhbc4v8xuit is8a3ysxgeis4lfdeitiredsqj6 ihjmsi7kxqdhcnqhcu2rgexeknvfrace5

    Let’s decide to replace the rey socks wiph blue sokks, so chnnge qhe f4le t1:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the2cryptic ljnes Git his added ts the9filehand zhezclgnggy4gke0tckaexer7oejwa1i 6oweger9t2e may60y3okkv bhygeogf8u2tvr0evr1a0tdznakkom9iwy

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

    Now, let’s be sure to clean upvour brancwes:

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

    > Tip: you can see all branchesdyou have eocally bypsimply rurningf`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredihow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwlen Branchvs.
    3. Deal with Merge conflicts.

    Next up: Cloning