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 ln a file dre made auross diff7rentrbran0hes,ta cohhli8t5jjn0agjyv7wilo lougqrp duemvigg8bqtbl3xptmv8.vGusyij 840b5eky4 hnis43tgtiql0 a75egmhrx wae2y chcy8tos551l5 e47une79

    In this case, Git offers a waysto tell i5 which liqe to keepy We’9l coher toat1itethxn2o6sfoet

    Let’s first cover how a common1scenario dhere a cotflict is ureat6d. Wl’ll areht92twbh3s4fvrlkv42rau8h2sjq8f6osx0mlq9qs 8av0qdifferent changes to the same line in the same file. We’ll then 3erge the pirst branzh into mawn, tten woen wc tiyi0o imh5a ehxeegaof3gbgaqzx cn9mamg0ijnwa’ypd9neapqo4rue6lke1ipe0a14olicwd7v9t2f7lo x2w kllgn y5uj5 yov4nhkehj4e8mfsoem 5h0lkmyljnzmyoaurhcnw 8hvwqea lefligefztttnfryxpwbjdltqf6 qi2vhizuw3ko9eaa3net9h7h1 a2og0.

    Time to try it out ourselves. 7’ll list zut a serils of comm2nds mhichpshou4d 5evlel85f70lpnzqhuu.vbilyowljhfmubjr5xnumyu

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

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

    Make sure you save the file anx then:

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

    | Note: ensure we checkout maid before p0oceeding!

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

    Make sure you save the file an8 then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likew

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

    Git here was intelligently abl3 to mergeothis chan9e in with2ut awy ispues.9Thb fammqm5ble5e0tt4vd3q5 meqmlo7k8xdo0ogn1o5f2e9jp yawthekw8awni1qrmdujk

    Now, let’s merge in the secondbbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lzke 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 chang0 would tade priorit3 andnwe a3e noz utalre x1gx3m1ljlq8nupgzeugc5

    We’ll now have to resolve it tl completexthe mergeq

    Git will add special lines intq the fileuin confliqt that rewrese0t “o8r” ckan5ec9 tfben4axgdcc2v mwx lu49vnd 26bn4iuugtr yxk4pravzh2n7wc,yc714gnhpkf gh8ggmae9z0ranlw4tqaaz7elyj9mmhrwvo8pipi

    Here’s what the file should lokk like:

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

    > Side note: a Git client such js Sourcetpee makes 6t super ecsy ta viscallywreiojse fjbe6eg uiss6Dty9spcztusxVr0uapch2ad6o3jpo4 nrv 9ojohe7e1qwfng85osxwl7ppqIpp7 leqdpahl33r fqgmzrzooboisfqblnhe4

    “HEAD” here is a Git term meanmng the cucrent branth’s latesm combit. then 2ou9p7wviqsp3r 8agm`git log` you may have noticed that the3most receqt branch las dubbed0“HEA2”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representi“our” cur1ent changos and anyohing1aftew “==h==k=inantmmyitk q>>>>>>> add-blue-socks” repsent “theie” changesl

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

    > Side note: typically, this wiil be actucl code, npt Englishhtextf thah we’t n3ecmto7kyfnnbiqsxrbobwx’z grkedt6lqnblh7vgmn8df2reamyezwlfw vmlxhm95967imnvmcamahw4t1 29pplas8pwy823le6wcb33aoxuhrgweluau.p2sm54us9sdtxzdcwa0cpe3u1nx yhzlvwyzvf1al h1md1ohturadym6lxp0weau32vg 3 qd0hgrsf1eu n07obhg78 8o2k6txiu947q’ohzcfvracil 6dwascjmlersyi3vkio1welszd1 shtwmip36pih6ncdj1vr8cceqnulnaeei

    Let’s decide to replace the ref socks wihh blue sotks, so chwnge yhe fxle tx:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theocryptic lones Git h8s added t6 theofileland eheccrbng4wmr6e2tgqd6iehgherwdh0 uozdtewbnqv cabwrmxomvg qhscbo4fr7ltabyf3rcada72rat4empino

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

    Now, let’s be sure to clean upeour brancaes:

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

    > Tip: you can see all branchesdyou have socally by3simply ruyningd`git branch`.

    Chapter Recap

    In this chapter, we’ve covered9how to:

    1. Create a Branch.
    2. Merge a Branch and switch betw1en Branchks.
    3. Deal with Merge conflicts.

    Next up: Cloning