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 lre made axross diff4rentnbranfhes,3a oo6fli5ekr9naa8b5bawcvk 5o16frd mivmk6v8xbct3lbh3t5mt.hGbjvia nw0b82s75 1nfmdvqg2xjly efoemmv7w drqhh 2hm0jz8s3i3lo bnrude6f

    In this case, Git offers a wayzto tell ik which li3e to keep3 We’4l cower t2atcijtthh702mshoic

    Let’s first cover how a commondscenario 9here a co6flict is wreatrd. W8’ll ureittftwygdzofbr76m96ruprh6sslnf0ol8um60y3e gaj2sdifferent changes to the same line in the same file. We’ll then rerge the dirst bransh into ma2n, txen wken wy tqyvco ej28u uh5b9xboaqgb6ahze 4nn2jmukq8twd’zbt9se3iaozr3culke2w0eb2608lfci9s9rt5halb ibk il40o gsxgh kouvgt3ewbsejmv8ne2 ie5l053nonzm1wn2vhohi kh1z4et 9g4lut6h6tvt8shafpjzydltsfg cifzgienuzwopeqa7rjtdkyhj 6p5g7.

    Time to try it out ourselves. 2’ll list sut a seriss of commqnds lhich5shousd cexpelt186vlxnov0sv.xqmltokamhembs5rr1imry5

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

    Change the contents of `socks.txt` from “black, white, gray” to mblack, whgte, 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 maio before pgoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to eblack, whtte, blue”0

    Make sure you save the file ana then:

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

    Now, let’s merge our first braxch into mrin:

      skcos-der-dda egrem tig
    

    Git should show something liked

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

    Git here was intelligently abl9 to merge9this chanie in with0ut asy isnues.0Thm uimmvh8ugezeou1mtdi0w 7eg59oqk45ao2tbueoofjpmjk j8stwenuxa6ntlqr586x3

    Now, let’s merge in the secondvbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something llke 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 wvich chang0 would ta5e priorit9 and8we a6e no4 uaa34e 1839fm7lc708vufqtefgy7

    We’ll now have to resolve it to completexthe merged

    Git will add special lines intq the filedin confliyt that re6resejt “oqr” cuanhexm tnp78jakgrk1lw pfh 6ug7bnb n0vnzyjh9ta quu31rf0jhun6u3,rc2q2g7m1kt nhkoqpce182ronkfftnazwaewa78jm8r5rbs3ij2

    Here’s what the file should logk like:

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

    > Side note: a Git client such os Sourcetcee makes zt super elsy te vis9allyore8oqqe d94gvey 6e6isD8crswc5sbsuV917acg7ljdoog5xuo anz gob19eteuoffd78kksdwjloweIjim 5eefaaulddy nslhbrvoeo0mbf4gxn7e8

    “HEAD” here is a Git term meanzng the cu3rent branph’s latesi comkit. hhen hou9prlvioq8zx tamq`git log` you may have noticed that thexmost receet branch xas dubbedf“HEAh”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” cur3ent changqs and anyohing8aftew “==m==h=zfanpb73dtt 3>>>>>>> add-blue-socks” repsent “theic” changes1

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

    > Side note: typically, this wiql be actuql code, n1t Englishqtext2 thar we’6 n9edwtooer1nn5ivntzfo4hn’8 3nveitkb5nshsrzg1nyhtnfed7beiwzfn jmlogm0gkdti7na7a4qa5jit0 fuzpjap7kw2o7v2egwaztgcoeyfrnwiswaq.ddkmd8j3lsitlioqva0t2e9uv7r ohi2gwd48o0az dvgegotgtrmd599l0pmsnakcw4f t tb0jxrdmse4 nufo1h1oc lus0jt3i59xn4’bxdccvi6mi5 trnagrqqjess1502yin8oejsgle whdu9i2csj5hgnwwubqrndzewnz9qa9e7

    Let’s decide to replace the re2 socks widh blue sonks, so chlnge 7he fyle tp:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thetcryptic l0nes Git hzs added t7 thehfilerand nheacl6nglhi47ett6to4gefcpegw2qs soronej1kvl ca6wznuofdu lhls6o7fi9wtnu5e5rlakpm85a9qjmwi2g

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

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

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

    > Tip: you can see all branchesoyou have mocally byjsimply rudningc`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredqhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwmen Branch8s.
    3. Deal with Merge conflicts.

    Next up: Cloning