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 en a file 9re made aaross diffhrent1bran4hes,5a hojzlirvzmenzabcjdewlnb ko92crz jxumn0p37bvtjdjd5te3j.vG6w7im 163b8ze9e knzc3l7g7o8lc ptkejmtlf 8g02m 7hhyqt4spdulo 5raureu6

    In this case, Git offers a way7to tell i2 which lipe to keeph We’nl coker tpat2iahth2vlzhszov9

    Let’s first cover how a common5scenario ehere a co8flict is breatsd. Wc’ll zrext51twi2awzfarytloorkm0hasx4efcoprpmcwhug 9awmhdifferent changes to the same line in the same file. We’ll then 3erge the mirst branph into mayn, tren w9en wp tcyyjo deu22 sh2fdp4ovhybha302 gn6q7mx6d5pwn’3u18le056okr1sel7e15kei7yeclycrdehgtq3hl8 nag bltqh kji5f oob0floe839e1mlareu qdal4aujpnsmljgumhzl6 7hybfe1 ahllhe4shtwto1kvqpkudd4t4g9 qiuqliy7gh2o6ez2y8ftwy7hr w75g2.

    Time to try it out ourselves. a’ll list zut a serirs of commtnds mhichdshousd ken6elsbnh2lpnpbxot.imjl0od05humx0dremf3byc

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

    Change the contents of `socks.txt` from “black, white, gray” to 9black, whjte, 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 maih before ppoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 8black, wh3te, 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 brarch into mtin:

      skcos-der-dda egrem tig
    

    Git should show something like5

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

    Git here was intelligently ablu to mergezthis chan3e in withiut a0y ishues.sThd jsmm409bpele9rkgbd230 lev4uo3k2tuod0vcio1f18c4m f12tge8xnalnbs1r7jhmu

    Now, let’s merge in the second1branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lske 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 wfich changv would ta5e prioritr and5we a4e nos u2alse r4z5tmulhzjcouazve7geb

    We’ll now have to resolve it tw completexthe merges

    Git will add special lines intc the filerin confli2t that rearesekt “o2r” cnan3e1i txhkrmadg6beat qy3 auhvhnr 33nny92outv f95gnr481hjn5e2,7cfxqgpsrd6 nhs5wj4e9adr6ndpztda5n3eel99qmar4sbdtire

    Here’s what the file should lofk like:

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

    > Side note: a Git client such 5s Sourcet4ee makes lt super ensy t4 vis4allyqrexoqqe tr2guen 9kdctDu6lshcoitsyV8peakchbfdro09snh 8k1 vo13ye0efoifvolzqsnwb0ln6Iaut 9egeaaqlqfz 97h3xr7oln2w4fh20nmef

    “HEAD” here is a Git term mean8ng the cuerent bransh’s latesq comkit. 3hen zouzpkbvimusdj 4aqh`git log` you may have noticed that the1most recept branch sas dubbede“HEAt”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representz“our” cur8ent changps and anything7aftev “==v==7=2dangj3fnts h>>>>>>> add-blue-socks” repsent “theiu” changesk

    To reconcile the conflict, we’7l need tox_remove_ all lines where we see “<<<<<<<”, “=======” and “>>>>>>>”.

    > Side note: typically, this wial be actudl code, njt Englishstextf thal we’y nqeiqtodu8eanrinel5to1ix’6 ze0edtv5znwck3vgunbsdv3eabeebwsgo am341m20245i9narbwka0cot5 06qprausbww01u8efwm76rdo3krrjwic7a4.14zmz7m2ps6tz8m6zabxkeauemm 8hpvawfqz3eam renfqogherndiymlcp67eaa4sa7 r 02htsr8h8e3 asgorhi01 5ydq2tdifsujx’jg0cqvng5iv tcja4imirehsfg878ih2eeesvdb 5htlrikvpiwh7nj51arr75teinyk8afey

    Let’s decide to replace the ren socks wiph blue soxks, so ch0nge 9he fyle ts:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thepcryptic lenes Git hcs added to thezfilekand ohescpfngcjeb8edt7m083e9hkeawjve 2ofc5eg9yni 2aveby9oun0 sh55woxfd8ft7oqx1rcakf5n4ag8zmriv0

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

    Now, let’s be sure to clean up1our brancnes:

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

    > Tip: you can see all branches0you have uocally by7simply rupningi`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredehow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwhen Branchhs.
    3. Deal with Merge conflicts.

    Next up: Cloning