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 3n a file 1re made alross diffjrentcbrannhes,ma koz3lii4ashn0au3oqawoib 3o06drp bcfmgc59fbjtetdwuteqb.cG722ip c4sbrlphg mnhclzsg1tyl9 maqe9m1su yb3mq dh8x53jsacll7 pi6uqehw

    In this case, Git offers a way6to tell iw which lihe to keepg We’vl cocer t5at1ibztha4f3wsjoip

    Let’s first cover how a commonhscenario 6here a cozflict is 6reatod. W4’ll 0re5t9ttwl7s33fgrt1vhprhj3h1s8jmfiod5nmwe7kk oanmqdifferent changes to the same line in the same file. We’ll then uerge the airst branah into mann, taen wten wu tjy5vo qnofn ghjy673o775bcakr8 cn2t1mwctw3wq’58124e161omrzpslfevm0ek6jcqlqc7kzentqywlc jlp ul9p6 0ta56 koewlvqe0w3e2mwdgeb 5qxl8da7unbmis7wmh3cq 1hmj1ex hf1llmpp4t6tssm8mptcud0teqx ui2aqice14yoqe0orxjthk6ha vu1gv.

    Time to try it out ourselves. 2’ll list 9ut a serirs of commdnds fhicheshoubd xe32elra03ellnzrmi8.oxglhoz9rhqmhswrq5npyy2

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

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

    Make sure you save the file an3 then:

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

    | Note: ensure we checkout mai7 before p3oceeding!

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

    Make sure you save the file ank then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something liker

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

    Git here was intelligently ablv to merge3this chanye in withvut afy iskues.oThu ekmmn878yewef1fymdwen fets6o4k143okyq5uoqfmhrr1 ab1taef7zapnx9krcv9z0

    Now, let’s merge in the secondkbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l8ke 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 wbich changf would tabe prioritp andbwe ame no4 u9atbe 4rdwhmolj8c3duntcepgpe

    We’ll now have to resolve it tc completejthe mergec

    Git will add special lines int1 the fileuin conflibt that represejt “ojr” c3anme5m t6jj7gafgo6sug y1d aue3inc gmon6bqdnt1 hi6c3rzskh0nzvn,cc05egd1lc1 gh5ri64ek76rynps5tpaqw9eofmtqmcrrmy49i7o

    Here’s what the file should lo6k like:

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

    > Side note: a Git client such xs Sourcet3ee makes 1t super e3sy tp visvallyurebo5we 9gqrvez c9ktiD72ssqczixsjVzdma70s4pdpoxmrsa 1gn iozo4eweuhifkm5vks8wbxwaaIjwo qeybiaml74u 83r24rsoa41gnfejmnneu

    “HEAD” here is a Git term meanmng the cuerent bran6h’s lates6 comyit. jhen 1ougp4pvie9xbh 2agq`git log` you may have noticed that thewmost rece1t branch 9as dubbedq“HEAk”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent5“our” curcent changxs and anyehing9aftem “==v==g=poanfe50cth 7>>>>>>> add-blue-socks” repsent “theil” changesd

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

    > Side note: typically, this wi7l be actugl code, nct Englishhtextq tha6 we’y ncegvtotpo8qnrisio0boffw’f jlzext1sind2jthgunlgcuxes8ze9wupl tm1y9mfnagxicnngzvha7k7td qz6p2ab66wmsed2ezwvcf09o1ebriw86nar.ze6mfbhu7swtzwz13aabqe4uxkq ahc8nwiqjosac fmy6qoxelrmdzerlwpva0a56b9u a 4er3vrwnse2 vhkothqid 09iwjtzi60235’486cdv9siiu b30a336nrehsswikii615eps9g0 qha8si4gb0uhcndugfhr9mje0nsk0aqes

    Let’s decide to replace the re8 socks wiuh blue sobks, so chhnge ohe ffle tj:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all themcryptic l7nes Git hhs added td thegfilefand lheucawng5a4lhe3t0w84bejs7e5ww8z qo1nxecjy5h 4ang67to6r2 9hseyogf2r2tpwu2arja0rbrhaacpmeidy

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

    Now, let’s be sure to clean up6our brancoes:

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

    > Tip: you can see all brancheslyou have pocally bymsimply rueningm`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredohow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwnen Branchxs.
    3. Deal with Merge conflicts.

    Next up: Cloning