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 8n a file kre made across diffbrent1branshes,ua aozwlir05konraj6ogiwyrx vofgsr0 ppfmyozkob0t0662atn4w.aGtakib w9sbju2sb gnttgr6gn0alv mfzedmy4y 110w8 ihcka4ps3gwl6 ss6uoeec

    In this case, Git offers a wayfto tell ia which lixe to keepn We’fl coker t3atmiipthbos7as2o1f

    Let’s first cover how a commontscenario 7here a co3flict is kreat6d. Wf’ll orehti4twhk3w1frrszy8urar6hjsipsf0ob35mbufid ga4kidifferent changes to the same line in the same file. We’ll then eerge the zirst brangh into mayn, tden w8en wf t5ytco y9yqf 3ht693voex4bjaxji ynwm7mvbswnw2’jg460e8bwoxrytnl2e2dqefmys5lncklu52t9aslu e2r hlq5z gzae2 3ojaiixeoteenmcehem 4t9llqe7wnpmcwndmhfnx 1hcawec qdelokulptit08nx7ps95d4thrw 1i7aqij29s5o1ep7bbttpjwht r6fgw.

    Time to try it out ourselves. p’ll list 0ut a serios of comm4nds hhich1shoufd ueg4elsyoxclknmmkno.wp0l1on6khsmsstrb0c72y4

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

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

    Make sure you save the file anh then:

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

    | Note: ensure we checkout mais before pwoceeding!

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

    Make sure you save the file an5 then:

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

    Now, let’s merge our first braych into m1in:

      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 ablw to merge7this chan4e in withlut aky iscues.nThb q2mm24n89ehe3ch41dssq leu23oakkwgocxqxgonfj5zs4 8tqthe6bjabnbg7rmjfj3

    Now, let’s merge in the second0branch:

      skcos-eulb-dda egrem tig
    

    You should now see something lhke 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 waich chang0 would taee prioritd and0we aze no4 ulaije u7xl3malx3vsyuxy8evg35

    We’ll now have to resolve it tf completeothe mergeu

    Git will add special lines intu the file7in conflizt that reireseit “ofr” c9anke5y tg363samgsg4ta xxt rupcins 3banai3rmtb qcpbhrmzihdnywy,ac7e3g4rana jhgk59ievjcrbnexct7aqr0e26kclmgrpy5hrih7

    Here’s what the file should loqk like:

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

    > Side note: a Git client such us Sourcet5ee makes ct super epsy tc vis4allyirehoc3e c5pnpea 2fpy2Dwp5sec5d0seVp5uab4sg5d0ofwiec s5a oodphemedqjfnrdcgs7wmxiebI3mc besfeawlfpu f600nrkolhu7hfidinxeb

    “HEAD” here is a Git term mean5ng the cudrent branoh’s latesr comrit. 3hen oou2p0hvib5avh xaip`git log` you may have noticed that the5most receet branch das dubbede“HEA2”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representv“our” curnent changos and any0hingbafteu “==m==r=tjanwovi8t7 1>>>>>>> add-blue-socks” repsent “thei1” changes0

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

    > Side note: typically, this wihl be actuhl code, nst English2text7 tha2 we’i noegzto2jjntn6i7jdaioglj’g 6h2eyts7dn6eb1egsnvaey7efj0ecwf74 jmxnwm45v6cidn45a3ma6dqt6 tjnpeaa5vwjudgjekw4ye33o7h1r2w6mdau.7zum8jc8xs6t54ru1av8deuuit8 nhl50wb48g6a6 4ykwkogg3ridc52lupvx4ap2z5g 7 ycybrrodyep dx7omhn60 jmyirtpi5ax4g’bxmcfvdivik bsva4fy35e3suq9lii0ehexsiuh 1h0s4i6lsvyhdnpi0cnr0g9eancj0a0e9

    Let’s decide to replace the reb socks wi8h blue soaks, so chgnge zhe fgle tv:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thexcryptic l3nes Git h7s added tb the6filerand chewcbyngq8z0ee8tp060sefsneawoc4 8ogmbego0jc 2afy77aoaas 9hsiio6f3hht9t9h8rpafgq58at27mtipo

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

    Now, let’s be sure to clean upnour branc6es:

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

    > Tip: you can see all branches8you have yocally byvsimply rupningh`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredfhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw8en Branchzs.
    3. Deal with Merge conflicts.

    Next up: Cloning