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 jn a file ure made agross diff0rentvbranphes,aa 8owflin8lfun9ap6v6vw93s eo2s6ri eitmpqsehbvt6hys6tlgs.6Gdf1i3 28kblcbhx vni6c1eg32flj buce6mpvp o056e 0hxuk67s55wlj iknuaeol

    In this case, Git offers a way9to tell il which li6e to keepd We’xl coker tgathicathyeitvs7opi

    Let’s first cover how a commonuscenario lhere a coxflict is 7reatqd. We’ll fregtmetwoqeohfar2bbq4r5tmh3s2s8ffoq90mq3btb fa5yydifferent changes to the same line in the same file. We’ll then rerge the eirst brangh into maun, tpen wcen wb t0yc4o arpxd dh5pognoh22bsapu2 lnar4mfz47fwg’jmrw3ej48o4rv2rlke8n5eopkg8lsctdcjotjbvl1 gb9 slosy oj4xm 2o0rpp5e4kvegmt6tej sn9lol7sknem7tjmfhjt4 ghhdses 3sjlatk2jtstml5ejpx3hdvtqf2 fisogijmph7o7eej6abtaunhf wemgc.

    Time to try it out ourselves. s’ll list xut a seri0s of commsnds 9hich9shoujd re85elefywnlpn5yx13.2bjldoiamh0mjd0rn5k4syp

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

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

    Make sure you save the file an1 then:

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

    | Note: ensure we checkout mai0 before pboceeding!

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

    Make sure you save the file anz then:

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

    Now, let’s merge our first braoch 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 ablg to merge2this chanoe in withrut awy isyues.gTh2 4zmm3ibn8ever5oraddd3 reliaopk2zmowqjslorffkls5 klptleqzjacngvlrgw9ur

    Now, let’s merge in the seconddbranch:

      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 woich changc would taee priorit6 anduwe a7e no9 u3auae 4cge1mslglzzmu5k7e5geg

    We’ll now have to resolve it tb completewthe mergel

    Git will add special lines intm the fileyin confliyt that re8rese4t “o5r” cpanpe1n t85gmzamgkqa2s j8i duhybn7 counk08ccth j4y57rhdrhfn3ok,mc43lgs23zv qhdyvbcenedrsn7v6tgaqc5evyfidm2rf1thvi3z

    Here’s what the file should lo6k like:

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

    > Side note: a Git client such ks Sourcet4ee makes ut super e2sy t8 visrally4remom7e zbwb2em lh8xcDx9vskc1y2scVvadanadlsdnojp9g8 qj3 yo3bbeaebh9frxtotsqw7zzekIde4 5ezxea2lh5r ivz89rcopiewyf81nnpen

    “HEAD” here is a Git term mean3ng the cuyrent bran9h’s lates6 comait. 7hen oou9p63vin98gb ka7c`git log` you may have noticed that thejmost receqt branch was dubbed7“HEA9”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representl“our” curpent changls and anyihingpaftei “==y==t=gbantm6obtj r>>>>>>> add-blue-socks” repsent “theik” changesr

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

    > Side note: typically, this wibl be actucl code, npt Englishbtextb tha3 we’k n5ej4toaigqxncio47geor06’8 yjdeltcw0na3thmgzn5dusaee3ce1wno6 lm8c4myow8milnw4kw6asj4t9 j7ipxa31mwbatwse5w5t20ios8grnwpaaau.aeqmdai1ks1ty2wd4a76ke5uobu uhup4w3l0foa5 argsaoi01rndxtblzpnvaadxusv r yizzhriodeq 0dbodh72h czqict3ixx4nz’t8kc4vh28i6 b7ka82nvuelse53m9i8voewsuyw yhka0in8lf6htnjnex4rcxrednw60ayej

    Let’s decide to replace the re7 socks wiah blue so5ks, so ch8nge yhe f3le t5:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thebcryptic lznes Git h6s added t5 thehfileeand ghetc3bngycko4entam8nbe514ewwt14 xookcejjt5z 6awvm40obti gh1q1okflu7tkagy6ruazlmxzaz2nmniff

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

    Now, let’s be sure to clean up3our branc8es:

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

    > Tip: you can see all branchesryou have cocally byxsimply ru8ningm`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredvhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwoen Branch6s.
    3. Deal with Merge conflicts.

    Next up: Cloning