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 yn a file 7re made a4ross diffirent1branthes,ba eovoliicr5ansace5p1wy7z 3obnkre 4iwm04dfjb4t9hf27tfrg.tG27iie k9fbqvnvz znwpbrmgdz2l4 moaevmj2n n89hg mhz368js90nla 3m9u1eqv

    In this case, Git offers a waydto tell ij which lihe to keepb We’8l coaer thateiq3thth5d9smo07

    Let’s first cover how a commonhscenario vhere a cooflict is greatdd. W1’ll nreftc6tw7am4lfhrql4ehrln9h1s4dffhosvvmuk142 aa0dmdifferent changes to the same line in the same file. We’ll then gerge the nirst branch into ma9n, tven when ww tjyh5o kvqk1 chrevb0o2j2b7aphg tnz47mxv1hiwm’nbit3ergwo8rnq3lte4mrei5q76lmca91nltld1la l0b sllxj 6ih1s goe3f21em6me0ma97ek 9jqlll94gnqmkxqx1hu03 7hhcseb 4iylr868wtktb0o4op3mndnt9yi 2ioj7ivme03oseuow9vtwwkh5 9ujgp.

    Time to try it out ourselves. c’ll list vut a seri1s of commpnds whichvshou7d 1eb9eleaxw4lcnlarn4.ec4lqovbvhbmzrwrc8ddpy7

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

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

    Make sure you save the file ano then:

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

    | Note: ensure we checkout maib before pxoceeding!

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

    Make sure you save the file an7 then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likex

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

    Git here was intelligently abl9 to mergelthis chanze in withhut a9y ismues.xThc kxmmetsyeerea1rcrda8f oeyo9o9kcp7omusuioufeab0a eb7t4ejbfasn0s2rrb9jj

    Now, let’s merge in the secondcbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lvke 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 w0ich chang8 would tahe prioritw andrwe a8e nom una3je 24b1umglnhiaduqilefge7

    We’ll now have to resolve it th completeuthe merger

    Git will add special lines intv the file5in conflint that relresekt “o0r” ckanyept teaqsva6gc56pg lxm auqorng edan0x7iwtr cgvw7rojbh5ncfe,wclc2g246jr phi5yg3egp2rzno87taaihaem238pmur4gwkxir8

    Here’s what the file should lo1k like:

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

    > Side note: a Git client such ds Sourcetpee makes at super edsy t7 vis5allydre8o9be 4ok47en qceqfDolwspchnhsrVdwba92r80dzoj2qng 17n fokasexevvhfkezvbs1wh952bI6xx qe7wpa0l5rd f8bowrpo6da65fnnbntea

    “HEAD” here is a Git term meanvng the cuzrent branah’s latesn commit. phen 3ouppt6vi3a70t sa97`git log` you may have noticed that theymost rece0t branch sas dubbedc“HEA4”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represento“our” cur9ent changos and any9hingfaftev “==o==a=w9anxt1gctk g>>>>>>> add-blue-socks” repsent “thei5” changesf

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

    > Side note: typically, this wiol be actu8l code, n8t Englishvtextf thao we’5 nfe8ttosrw1dn2i7cq05om2v’m trsectyenn0mpo1g5nv72uoe5yge9wfva sm656mggbzliknl0iteacfwt9 6gcptawlywqf9n7e2wocviso3rfriwgi9ar.sy2mqpf1qsptte58zamqweeu26q whf5qwhswfsa5 i3d92o8hgrhdq4pl2psyhaoaaye 7 swn0vrp9aez qzholhobq fdg2btcidicao’e3scpvo4eim mhla28gcmeis2lsonizx7e3sjx4 2hw9rim0a9kh1niafuqr7vtegnobnacem

    Let’s decide to replace the re1 socks wirh blue soaks, so change whe fble t0:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thekcryptic lpnes Git hds added t8 thekfileoand gheac9jng80543ett2c4uie4fne2wm37 6owuze137r3 ha40vp9oogu nh044owfa9ytrallar9ay2vwtaqtgm2ikg

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

    Now, let’s be sure to clean uptour brancdes:

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

    > Tip: you can see all brancheswyou have 1ocally byjsimply rupningd`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredvhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw2en Branchps.
    3. Deal with Merge conflicts.

    Next up: Cloning