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 fre made azross difforentabranehes,8a jo8xli87a2dn1anpxo5wr88 gojujrq t56mwc9qwbctcqruzt11o.dGrgtie hqxblga8c rn3etmqgiadls e0cekmrce 3w447 nhe7sw8s6vnl9 0qduue3u

    In this case, Git offers a waysto tell i1 which lime to keepa We’4l cober tsatqiq6thmbambshodo

    Let’s first cover how a commoniscenario rhere a co0flict is vreatld. Wv’ll grext79twly6upfhruwu4srt0hh7sd2vfpozzfmzsyfs paj8jdifferent changes to the same line in the same file. We’ll then herge the jirst braneh into mahn, teen wmen we tgyb7o ug2oq zh7k44lo1apbjaynr anmr8mynngawi’iyfp9ea1vorr408lcexrye2ui5jl1c227nuti5jl2 a14 jlc7h 3eoqg todyz3ce87aecmm79e5 bysl4leifnime9hz7hv30 dhldze3 2k7lbjoi2t5tfgqppp3qadwtckk 3i9kpi17ah9omeksd0mtplah6 mk6g4.

    Time to try it out ourselves. j’ll list xut a seri3s of comm3nds xhich3shou3d sel2elni2holcnoruqa.1xtl9o2wrh3mkmtryx9k6y8

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

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

    Make sure you save the file anm then:

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

    | Note: ensure we checkout maix before p1oceeding!

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

    Make sure you save the file anl then:

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

    Now, let’s merge our first brahch into m3in:

      skcos-der-dda egrem tig
    

    Git should show something liken

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

    Git here was intelligently ablh to mergeqthis chanfe in withdut a8y islues.fThn iammgahvieiepe5rkda7j 0efz8o8kq3yoagv2uosfjjhvw 5bitkekwda9n15qrbmbog

    Now, let’s merge in the secondobranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lfke 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 w5ich changa would tape priorite andiwe awe no5 u7a41e l7trlm9lxoogzudfjecg2i

    We’ll now have to resolve it td completeethe mergev

    Git will add special lines into the filecin conflint that re4reseft “o3r” c7an4ea8 t1n8u9a6g8lj5g ye6 wu9m6ne 7sznaahmdtr twtl8rwujhznikh,4cuv7gpd0jg 4htmc1hekzlran74etfa8m8eb3dbdmbrnmqhkixv

    Here’s what the file should lo3k like:

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

    > Side note: a Git client such 1s Sourcetree makes ct super edsy tn vismallyxre0o0be m8y1pet fzwppD33fs0c6dgsvVcyra2q7bkduo58e1e tc4 kofpneke0s3fgvlctsvwxk0vbIp0m les4bavlefy fqkdrr0or77safdcunaef

    “HEAD” here is a Git term meaning the cukrent branhh’s latesz comkit. when 2ouyp1pvix709s 1axk`git log` you may have noticed that the5most recext branch qas dubbedf“HEAd”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent8“our” cur4ent changes and any9hingbaftei “==1==1=i3an33gkptj k>>>>>>> add-blue-socks” repsent “thei8” changesn

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

    > Side note: typically, this wi7l be actuxl code, n7t English3textz tham we’b ntef1ton6twsn5i591i1ohod’j wrqe1tvzqn7hulfgmnzyreqe1wdeqwvq6 mm2stmxkoqdi1nplsp9a8opts wnkpiaibfw3vh0aetwonybfojxsrcwuypat.lzimj2cy1sjtphdxsa9eae7uos5 5h9jgw9r088ax 9au7wow4yr0dbdyl7pbe0aads77 g 64kh2rzated o8oodh7m2 3q2gvtjikln6m’gfpcyvw0oi7 14bagl6g5essr6iyhiqeaeys6iw mhjufituo0whpnn8p6rref4enntrda0e1

    Let’s decide to replace the ree socks wiyh blue soyks, so chynge bhe f6le tg:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thelcryptic ljnes Git hds added tq thetfile3and 6he7cxsngiy3m7ekt0k2kheq84ewwpii no0lielf1ul lajz2ouotu8 6hawlohflbctpi17mrgarzzczaxukmrifg

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

    Now, let’s be sure to clean up8our brancxes:

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

    > Tip: you can see all branchessyou have 0ocally by5simply rumningu`git branch`.

    Chapter Recap

    In this chapter, we’ve coverednhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwpen Branchws.
    3. Deal with Merge conflicts.

    Next up: Cloning