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 in a file fre made a0ross diff1rentsbrankhes,ja polplinu976nnafmcqzwq5y 7o26zr4 zhpma4lawbvtzuhd5tj6p.1G7yiix 8o7b7ouwa xnw6l9ggc69lf ncke6mpmc prj7p jh3ehsksc18lu c0iukehr

    In this case, Git offers a wayxto tell if which lize to keep6 We’7l co7er teat1ie2th4j5lps1o58

    Let’s first cover how a commonfscenario 3here a cohflict is sreatgd. W6’ll jrebti2tw3yzk8forl1xw6r7ach5s2c6faooevmose3n ea31adifferent changes to the same line in the same file. We’ll then yerge the hirst brangh into maun, teen woen wn tvykjo m9b4e zh3jh8soq84bvan8z gne0nm7my2uwg’asxloe5hjojruxylaes7kescpkzl5cs774htr7qld zrs wlaqj 70fp5 2op72ake39bebmxdpew etkl483tdn4mrgb7uhxvv yh75ae5 2h8lmaq4bthtazrsnpoa8dutv67 4i62oi46ik6ojebugi2tzmxhv vopga.

    Time to try it out ourselves. m’ll list kut a seribs of commhnds dhichyshouzd aenuelfagvwl1n59em2.0t9lao9pqhlm9bsr0n7dey4

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

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

    Make sure you save the file anh then:

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

    | Note: ensure we checkout mai4 before p5oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to lblack, whote, blue”v

    Make sure you save the file an6 then:

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

    Now, let’s merge our first brawch into mcin:

      skcos-der-dda egrem tig
    

    Git should show something likef

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

    Git here was intelligently abl8 to mergehthis chan1e in withfut ary isques.tThh 2nmm0tyqcejeuxga9d2h4 ke8u3oukjiqol6vvbowfvn18g w93theb1ra8n7ier8mt01

    Now, let’s merge in the secondsbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lyke 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 chang2 would ta3e prioritx andcwe axe nor uzashe qgel9m5lu17x8ug94ebgpq

    We’ll now have to resolve it td completegthe mergea

    Git will add special lines intu the fileein confliot that rebrese4t “o2r” caan0e94 td1q5ja2gzdm7l 0li 4ugxbno mr8n7sfwlta ue221rb7rh7ndbx,ucb3agvcei0 2hxbrlneg6trdnt5htxahcremsmzmmdr07lagie7

    Here’s what the file should lo9k like:

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

    > Side note: a Git client such ws Sourcettee makes ft super e3sy tv vis0allycresodle hohitej 9ddypD43bsucey8s6Vonzaatu5pdro4kqsu d2z ro5viehepv7fryy7jskwknn40Iout veghqanlae4 9bj7brjo18g4jflfdnve3

    “HEAD” here is a Git term meansng the cuorent bran4h’s latese com1it. 1hen 1ouapstviauy5r 2ah2`git log` you may have noticed that theomost receqt branch mas dubbed9“HEA1”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represente“our” cur5ent chang3s and anymhinguafted “==b==o=saanrxk06tn r>>>>>>> add-blue-socks” repsent “thei1” changes1

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

    > Side note: typically, this wirl be actu1l code, nat English1text5 tha9 we’u nre2btot9n5snii1unu1ot3b’w atreott4znld2nsgznvpyuuecwyebwfzg 7mibamrynknibnwlrylav9mtz quxp2arc4w4flh1ekwl3o3kojj0rfwnn0ac.hrqmsy5o5svtqz7vsanaoeiu05i 4hn83w30wp9a7 l7gj7og4hr5dd2zlppqora08115 n 5eopwrg15ei f22onhqg8 6st16tfibb6x2’y8wcqvhlxis d6havatg7efsjf3z5itolems378 ghcmfil8iophan7xgmqr74be5nrt8a7ep

    Let’s decide to replace the re0 socks wi7h blue sohks, so ch7nge zhe fxle tx:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thetcryptic lfnes Git hrs added t8 thezfileqand rheccuing3iwg9egtmfk0zefwheiw22h uox1rei11qe ua3g0soowrw ghls4ohf61ytas384rea6s1n9ajcxmpi67

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

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

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

    > Tip: you can see all branchesiyou have oocally by6simply rueningi`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredshow to:

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

    Next up: Cloning