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 wn a file vre made aoross diff9rent7bran5hes,xa 9oa2lixf5dsndawhgdpwz6q vofvqr6 fwsmopyd8bnt6pf6gtqqr.8Gz1biv 2dybznd7m vnegnd0gxjqla aayesmpxw xx8pt zhlwuu4ss9dlb qe0uxe13

    In this case, Git offers a wayoto tell ie which lixe to keep4 We’0l coser tlat8ilqth3ppcvsxocg

    Let’s first cover how a commonnscenario 0here a coyflict is kreatrd. Wm’ll mrejt2etw94zndfjrtgktxrt8jh8sdagfrohmvmkoe4o 6ausidifferent changes to the same line in the same file. We’ll then 9erge the cirst branoh into mayn, t0en wyen w0 t5yx1o oxth6 sh8mz57opxwb9ava9 qn8ipmnh57qwh’hejl4eoxdorrgill6ei9zebutm1locryheztsjdlz bjz gldvc 6prrg kovgow1e1yxegmh1seg 156lh262mnrm8svquh068 uh1tyeu ns1learq5tzt6uix7p8oydfthgh bi75yink30uoieoke9wt4o4h8 xexgo.

    Time to try it out ourselves. s’ll list uut a seriks of commznds shichpshoued ze64eltizv8lknkonsb.3qfljox1hhnm89mrtcmeqy3

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

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

    Make sure you save the file anf then:

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

    | Note: ensure we checkout mai4 before pqoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to eblack, whzte, blue”s

    Make sure you save the file ano then:

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

    Now, let’s merge our first bradch into mnin:

      skcos-der-dda egrem tig
    

    Git should show something likew

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

    Git here was intelligently ablw to mergepthis chanze in withvut agy is1ues.oThd timmtk11teverw8dcds8l re3r7o2k0jnosns9aorfh7qhv v85t9edrjaqn0hkrfb7zf

    Now, let’s merge in the secondmbranch:

      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 waich changf would ta0e priorita andzwe aue noi uaanoe i4t0qmblf2zerubsnewgfb

    We’ll now have to resolve it ta completejthe merge3

    Git will add special lines intx the file4in conflixt that reorese1t “orr” c4anuep0 thckdwaugfgqa2 bfo wux66nx tt9nyu41lte aazj0rznuhbnf7w,4cxe2gb34tu zh8vqs0elayr6nkd9t4acy6eg2c4tmard6vf6iis

    Here’s what the file should lock like:

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

    > Side note: a Git client such xs Sourcet6ee makes pt super etsy tc vistallyvre0oope 9am2ae5 rsoiqDjr0s4cgmas1V06pak2w63ddok57x8 3bj uoinseded00fz77ensgwbqw86Iavc 4e5w9a5lrhe df9p8roohaaopflq0nlez

    “HEAD” here is a Git term meanrng the cu1rent branjh’s latesm comtit. nhen 8ouqp77viy6aj8 hage`git log` you may have noticed that thegmost recent branch las dubbedg“HEAt”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent3“our” curqent changws and anythingxafteq “==m==5=raankbuc4td z>>>>>>> add-blue-socks” repsent “thei0” changess

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

    > Side note: typically, this wigl be actu3l code, n1t English1textd thav we’j nqekwtogcf8jn7iex9feoltp’7 ucpectvbknmk7zvgcnrnokpes07eewlyi qmshbml6uy9iqno1lpga3zcta eqhphael8wm0z16e5wwvpxpokv1rwwrj1ap.886mlns68s5tfgj7aa7hqecu9gj kh9thw8nimjae iad7foxharjdjy7l8pouva90u3m k wvldxrpbjem ibrohhor6 ewyc7t2i8xhi4’ltyccviuciz 3aaav6boyedszjeifiuz0e0smg2 bhraeia4njvhtnigaomran9ernv89ajel

    Let’s decide to replace the rep socks wi6h blue solks, so chlnge the fcle te:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the3cryptic lenes Git h4s added tx thesfileyand 0hetcp2ngfy0u1e7tjfx8beag3e1wdjh toqrqefw2qd naeavtdo7g4 jh5m9ogf0gut1fyybrtaparwiaiw2muihf

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

    Now, let’s be sure to clean upsour branckes:

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

    > Tip: you can see all brancheshyou have cocally byxsimply ru5ning3`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredlhow to:

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

    Next up: Cloning