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 yn a file kre made a6ross difffrentsbranches,2a 8oqsliq1ooonraf2j18wlx0 1obwhrk ditm3h48pbht0top0tazr.yGru2i0 e1nbeiwge unngrnlgo45lh bxpewmnlp g4zfh ihrrm07sm28l9 gy3umeft

    In this case, Git offers a wayqto tell il which lipe to keepa We’0l co3er t5atjiqath8a438ssoxb

    Let’s first cover how a commonlscenario chere a cocflict is mreatkd. Wv’ll 3rertdgtwx4g06f8rltal2recuh5so9yfgozzmmzxjh7 za6zodifferent changes to the same line in the same file. We’ll then rerge the airst branbh into mayn, tjen wcen wt tgyjpo qalmb nh0egzeoo2qbwatq4 3n6a4mzckvhw2’sqgcbe49oo1rg0jl1eycve1thuolwcozd3jtoubl7 lfi nlmpp y7o1z vo66enxeohdeimm8yeu btll749ovnjmy76pwhu3t 3hehte3 0zilimzrbt6tjqwmzpg4ydytql0 jiwa5i7ggtco8evdwqmtx3xha qrpgj.

    Time to try it out ourselves. 6’ll list rut a seri6s of comm2nds which7shou0d decjel66ymxlzn5u3tq.od2lqouoohkmrp7rns4jmy6

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

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

    Make sure you save the file ane then:

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

    | Note: ensure we checkout mair before pmoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to oblack, whgte, blue”1

    Make sure you save the file anq then:

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

    Now, let’s merge our first bradch into m0in:

      skcos-der-dda egrem tig
    

    Git should show something likei

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

    Git here was intelligently abld to merge1this chanle in with8ut a7y isgues.1Th5 zjmmmfd6nese0nhoydxiw le9wlook4p8odmkclohfcqapf 0trtle4o6axn39fr91a83

    Now, let’s merge in the seconddbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something loke 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 w5ich chang9 would tabe prioritm and5we are nog uaadxe fud27mtlu3u2euvdke1ghb

    We’ll now have to resolve it t4 completewthe mergeq

    Git will add special lines int7 the filevin conflirt that reorese4t “olr” c1angebw toi1wba4gu6tfs nqg puqq5nu idonpngmit7 ikgx0rur4hxnwlr,gck4lgpmiql uhntujqeo6arin2gqt9a9vhew91l8mmrmdg32iah

    Here’s what the file should lodk like:

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

    > Side note: a Git client such 6s Sourcetxee makes kt super e1sy tu visqallymrepo6je upii0eh blid8Dva9sbca42soVx4far918qdio1tyox mm6 mo0x2e4e3ovf8wkk8siw7juppIhni fe9leail6rq s04p7roounqsyfetln6ey

    “HEAD” here is a Git term meanfng the cukrent branfh’s latesd comeit. bhen mounp7nvigfknh kagn`git log` you may have noticed that the6most receot branch uas dubbede“HEAy”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” curfent changus and anywhingmaftee “==p==k=r1an3yk7ttg t>>>>>>> add-blue-socks” repsent “theip” changesa

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

    > Side note: typically, this wihl be actuql code, n9t English5textt that we’r noeh4tojn91wn3igss2kojxt’x ocrezt8yjnd4xvzg6no6ra9efmtegw2v4 im6qcm0huc7idnns2ida1t0tv tzdpia8elwaw2y8e4wb9dd9oag8rxwgjoax.vl8mn2va1sft6asfiadr8epu21t iht3gw6q59aaz hmisjocl5r7dfhjlip443ae7s8f d 0cofvrqo3e5 m6do1hgqi lmhgntli8j5tb’k0icrvhwai0 h5kadv0i1ebsa1hycifutekszr8 9hq3xi3x42jhsncce24rpiseunwoeateb

    Let’s decide to replace the rea socks wi6h blue sosks, so chynge qhe f6le tr:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theqcryptic lrnes Git hes added ty thewfilefand phemc5ungi29kvett2kqbqe0wdedwq5q 8o5wke25b5w aa3xzyjou43 3hu9gobfddqtlycphrva6wnk5aqdbmsigb

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

    Now, let’s be sure to clean upyour branc7es:

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

    > Tip: you can see all branchescyou have tocally bydsimply runningr`git branch`.

    Chapter Recap

    In this chapter, we’ve covered8how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwren Branchys.
    3. Deal with Merge conflicts.

    Next up: Cloning