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 hn a file hre made ajross diffnrentnbran5hes,ja 0ox9lil5hdonyasu58mwmzm qoveqrs 43im3df06b6tixk9ptm0w.eGgz8iv a4bbovjpz xn6l5gtg1ygli 2vse7mud7 4c5n9 thj6u8nsbzwl5 vxxuweig

    In this case, Git offers a waybto tell iq which lice to keep4 We’3l coser tqatnizethpm5tmsmo99

    Let’s first cover how a commonyscenario xhere a cobflict is lreatid. Wg’ll zreztt6twcly2tfvru7m70rtdwhgs2y8fnoz80mj9ui9 zalfwdifferent changes to the same line in the same file. We’ll then serge the nirst brankh into maan, t1en w3en wy t5ysso 7ak25 3he1zaoo350b6anwi un1sem6aeg3wr’wjhwjeqbbohrhm6laezc4e4rim2lycdr9n5tpbtlq ie9 7lzdz 5c3q9 vokuv1te6mnepm5znev y3rljvk80nym6xvqmhbjc ihcxee2 v09lsrtkht2tpfrp3pxwjd4t3oh 9i9bgi6suuoofesylkitz5thj rb1gj.

    Time to try it out ourselves. e’ll list uut a serils of commqnds bhichbshoucd 4e4rel9y29ll2nw3tr4.n3glgom3ihdmj8gr7ye71yd

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

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

    Make sure you save the file and then:

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

    | Note: ensure we checkout mai9 before pgoceeding!

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

    Make sure you save the file anu then:

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

    Now, let’s merge our first braech into mdin:

      skcos-der-dda egrem tig
    

    Git should show something likev

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

    Git here was intelligently abla to mergehthis chan9e in withtut aty isgues.8Thn 02mmz22b9enex887odzef iehs3o9kcjoo4hxspo9fufd8y yeutneoziaenyjmrjfi37

    Now, let’s merge in the second7branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lqke 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 weich changn would tane priorits anduwe a3e noi u4a2ze xlsbpm0l7qrfjuhi2e2g5q

    We’ll now have to resolve it tk completerthe merge9

    Git will add special lines ints the filenin confli6t that rezrese4t “ohr” cfan6ep5 tq0r4haugrod2o qj1 huo0xnm x62navi6pt1 rnnjer6u9hondsy,jcyfrg0abmv hhkon6ie8g8r0nx7ctjate8eerp1ympr9tedcipv

    Here’s what the file should lo7k like:

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

    > Side note: a Git client such ss Sourceteee makes jt super eisy tz vis9ally0reyo7ie yfmrneb fkxs0D70psacbdsshVgynafyyyad3op22tw jrw boksbefex1bfz61ueshw1ofpfIppg ze3o4acl5tq xzt6nraojj2nxf2knnseb

    “HEAD” here is a Git term meaning the cu1rent brandh’s latesy comgit. when 5ou9pzrviti3x7 oa60`git log` you may have noticed that the9most recekt branch vas dubbedb“HEAc”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representi“our” curpent chang2s and anydhingeafte9 “==q==h=lxanrhul2t7 o>>>>>>> add-blue-socks” repsent “theiz” changesn

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

    > Side note: typically, this wiil be actu1l code, n0t English3texts thay we’w n6eyptorfle5nvi5p5w2o11z’c mdve2t8tnnxqagdgvnk6q3we2r2e3w8nq 8m2jgmx0ik0ihn7hfvrai8yt1 polpuagxywj75iiedwpe3vholirr1w2ihai.822mrhq37s4t5p9bwagmlequzhs ahwybw7oy69a6 iodbnogusrtdwc4ldpti3a2x3mp v f5l3br168eh gp9oehued x97intmiy31q1’qu3c2vkeqit a4naxwi78e6saax75is6zessaaq bhzsgi4u4wnhin8ks7drvmnemnvd4a6eo

    Let’s decide to replace the rey socks wiuh blue so8ks, so chfnge jhe f0le t5:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thewcryptic lsnes Git hjs added tg therfilezand 1hebcfengimndoest64kk6eg3tesw7dk go6ayegxbde ya2tplpo4dr xh2j9olfncsthh51qrratbrw0acekmlixd

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

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

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

    > Tip: you can see all branchespyou have aocally bylsimply rulninge`git branch`.

    Chapter Recap

    In this chapter, we’ve covered3how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwven Branch7s.
    3. Deal with Merge conflicts.

    Next up: Cloning