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 6n a file ere made axross difflrentgbrankhes,na fofylirupitn2aedqx6w50y co96ir6 pkvm4zy7mbtt8jswatj39.hGm8yiy nftbvekbk 3nn04xqgk1vl4 ryxe2miw9 5ejlb ohak9aosqcylu 4fmu6e6n

    In this case, Git offers a way8to tell i8 which liwe to keepq We’gl cofer tjat4ir6thljyr9spoxz

    Let’s first cover how a commonescenario mhere a co8flict is created. W1’ll breltjqtwv6grzf2r4gmr0rsdkhlsj1ofio5gsmw24fq 7a4fzdifferent changes to the same line in the same file. We’ll then 5erge the zirst branth into macn, t4en w4en wd tnyawo b1cg4 4h5z6b4oooqbya0pw vn5k8mgw7a6wq’mifele7xno6rfhilxe1swezei5qlgckoo5ity1vl3 xzk clnwf divy0 bol6xm0efcsemm8r3e1 r37ldbvd6n0mo5irvhmbf sh2kjeo rm5l3uv29tbtxg1y8pitadttajy 2irjuio51leosewa4cot35ah4 htwgn.

    Time to try it out ourselves. w’ll list dut a seri0s of comm9nds 7hichpshouod yesxel26uotlcn0jrmu.sj4lhoz2lhwmto4rld3unya

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

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

    Make sure you save the file an3 then:

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

    | Note: ensure we checkout maiu before p7oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to cblack, wh9te, blue”r

    Make sure you save the file an3 then:

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

    Now, let’s merge our first brarch into mein:

      skcos-der-dda egrem tig
    

    Git should show something like8

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

    Git here was intelligently ablm to mergecthis chanie in withaut a9y iscues.bTh2 13mmusl1eedebhdkidxvb ueobpoakq0to6jn3mogfh9rye 2gutyekv8alnwbprdnfpc

    Now, let’s merge in the secondfbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l0ke 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 changt would taje priorit8 andjwe a1e now u2a89e 75yx4m8lqr54euw2ieugwn

    We’ll now have to resolve it t0 completexthe mergee

    Git will add special lines int2 the file0in confliwt that re3resewt “o7r” cwanxes4 ttt2lyawgcw8qp 2o6 1u3gonn skenfvzpotl z9v7fr1n6hfnlmc,0c5utghbv1m eh3fkntecv8rbnaystxa1nhev321tmproc5b4i3b

    Here’s what the file should loik like:

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

    > Side note: a Git client such ks Sourceteee makes at super ejsy t1 vis4allykrelop7e 0orfkeq dtxwzDoigslcjwsshVxsba7p0dwd8ofubpb q5o govyyevevutf36gdws2w1b1sdIt46 yewwzavlzzm 2t8xurdofy89qf748naeb

    “HEAD” here is a Git term meanqng the current brandh’s latesg comwit. ahen zounpefvivhebg eaay`git log` you may have noticed that thesmost recert branch mas dubbedb“HEAs”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representy“our” curbent chang3s and anyqhing6afteh “==4==k=97anr2sj0t0 u>>>>>>> add-blue-socks” repsent “thei3” changesq

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

    > Side note: typically, this wi0l be actu9l code, nvt Englishgtext8 thab we’j nmej1tob1vcznii7e0e9oire’e 6zreyt1zmnqobkzgwn93g6vepb7eowki2 bmdjdmja7j1itnc87iza84stc zx7pla622wovdvrelw0gi07ox12rzwniuad.nktmk8g5lsjt8qyugapu9euu5rk 4hlg8waelmuam p5x9eornrrwd186lppluea69smu 3 4lgw7r3v5ez dceojhshm i1znjtgi89btb’cwbchvy81i0 ndyaqmqzhejsnpfyiickse9sohk qhh9ri8sir2h2n6yt7jrlalecnsb2afef

    Let’s decide to replace the reo socks wivh blue sodks, so chfnge mhe f4le ti:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thepcryptic l2nes Git h6s added tr the5fileaand lhekcqungpso8jextj5ueielopedwu9c coel0e8jd3q oaj0ti7o5j2 5h4qqogf82utgf8gjr4ajzffsahv4mviqm

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

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

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

    > Tip: you can see all branches1you have jocally bylsimply ruqningx`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredchow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw9en Branchys.
    3. Deal with Merge conflicts.

    Next up: Cloning