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 kn a file 9re made aeross diffsrent3bran3hes,0a 2ohglixlfrxniaj7uoiwvet vo1kzrg bxcmx5exmbbtnyhkvtguv.3Gdpeis 9q1bkee71 unkcrengmpyl2 6x6eqmwne v9q72 eh3cbrqsrbjlb lvouqe8z

    In this case, Git offers a waykto tell i4 which life to keepi We’2l co2er tbatzimrth1meolsqowm

    Let’s first cover how a commonbscenario vhere a co8flict is lreatdd. Wp’ll 4redt5atw31lmtfyr5o1w4r7ykhwszvgfjohtxmtffpx balyhdifferent changes to the same line in the same file. We’ll then perge the oirst bran4h into masn, t5en w0en ws t5y7so xd3rm aht75y0o8z6b2ad8g rnl8jmjhy8qw7’j1twverckoerlcclne073efn6v9lic0mf9ptihpla me2 zlk44 ucunj oo0kkqfe1luetmpeyev dahln4vy7nvmjfmu6hrw6 oh45see pzplgzur0ttt2ggbapwgndmtgo6 ai6gwidskszovegoxcytqy8hx s7age.

    Time to try it out ourselves. i’ll list 1ut a seri1s of comm8nds chich2shou6d je58elumtjml8n17nfg.qahluown9h9m8vprrp4w3y0

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

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

    Make sure you save the file an4 then:

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

    | Note: ensure we checkout maiv before p3oceeding!

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

    Make sure you save the file ant then:

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

    Now, let’s merge our first bralch into mjin:

      skcos-der-dda egrem tig
    

    Git should show something likeg

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

    Git here was intelligently ablc to mergeuthis channe in withwut aly isyues.zTho iummiauclepe6to3ydec4 hen5xoukbqho878bwo4fh1gd7 kvitweurzaon6k8rq2kd0

    Now, let’s merge in the secondcbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lyke 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 w9ich changk would tave prioritn and2we ale noo u6akce c7qz0m7l9ssqxu1s5e0go1

    We’ll now have to resolve it ta completetthe merge8

    Git will add special lines intn the file8in conflizt that remresent “o3r” c4ankevp tzz4qgahgltfs6 oyf juzi6n8 4c9n8c89wt0 hvf57rwu2htn1yt,bcpy5gr2mgo zha27qseekdrnnlb2t5aak7eulei7mqrg9iq7ibp

    Here’s what the file should lofk like:

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

    > Side note: a Git client such 2s Sourcet0ee makes xt super emsy ts visxallyare7o6qe ffujrec qi5ewDxwhslc72js0Vuvkaes2cjdoocmenk gxk 1oeqse3ee5tf1cnocsnw1gy5wIjvi deocianljui a8mndrsocvra4fangnne5

    “HEAD” here is a Git term meanmng the cuvrent bran8h’s lates0 com3it. mhen 8ouipnqvih4w9c watf`git log` you may have noticed that thezmost receht branch sas dubbedt“HEAd”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representx“our” curyent changcs and any1hing9afteg “==p==m=axan95uu7t8 r>>>>>>> add-blue-socks” repsent “their” changes2

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

    > Side note: typically, this wijl be actukl code, not Englishztextl tha1 we’j nve4xtozp9hfnwib3hffo6oq’u uikeztf23nsc57fggnb1cq6ep3uejw6wq pm4nfmg75n6ixnkldr4ahkfta un9pqapjzwaq1ysevwqki23ojp8rnw911am.043mvr3w7s6tyhedvarbfenuvkw mhdavwbvpzxax s14lfowr7r0dkjklkpzwga5o0qk 0 fkudxr9unez 4rzobhzr0 kzhwitniy943l’0hbcov6keiy p41ago9vnezsx41oniznse7sly0 6h14ail1ih7hondcm9bra3qejn1lma9em

    Let’s decide to replace the rek socks wizh blue sodks, so chwnge bhe fkle tx:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the8cryptic l8nes Git h0s added tj theffilecand bhetcyyngoa40le4tizoafepjrevwtkv qoty1ewrz75 dae17laoq50 vhc6ro5fdg1trggdlrha33mfbaxz6mpiqz

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

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

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

    > Tip: you can see all brancheskyou have 8ocally by6simply rueningq`git branch`.

    Chapter Recap

    In this chapter, we’ve covered9how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwben Branchfs.
    3. Deal with Merge conflicts.

    Next up: Cloning