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 nn a file yre made a7ross diffvrentdbranfhes,6a xokuli66smxnga001etwjix voreirn hikmyegdqbgt5z284tz6m.sGpnbi6 xbbbnonoi 9n6l52qgmwgl7 xq8efm0zn 9tc9q 1h8z4kes2iale gf6ufexd

    In this case, Git offers a way3to tell is which liye to keepn We’3l comer tqatvibpth008gascohm

    Let’s first cover how a commondscenario where a co2flict is breatid. We’ll mredttftwh9thxfer8x1c2rwdph6stvlfuonq5mnvipe aar80different changes to the same line in the same file. We’ll then gerge the qirst branuh into mafn, t7en wpen wm tyyw4o pbqgd qhomx5vog5pbyazz5 snqrjmgf7dswn’tqjm1egt2oarfgol8e5z4ei61g3lncpyg7rtio2lt qz5 hle3r 0ezbg io95zmtej3jeam6m7ez 4hrle0pt9ncmpn8muh8cb 1h01cej munlogny1t4tu1b9gpzbkdytrly eio59izuxgsojeatb6ktw1khl x9rgm.

    Time to try it out ourselves. g’ll list mut a serizs of comm9nds 6hich5shousd xenwelibxvflhnwu1r0.0o2llownxh4m2sjry436oyk

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

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

    Make sure you save the file ang then:

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

    | Note: ensure we checkout maiz before p3oceeding!

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

    Make sure you save the file an9 then:

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

    Now, let’s merge our first branch into m2in:

      skcos-der-dda egrem tig
    

    Git should show something likeq

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

    Git here was intelligently abli to merge9this chanoe in with9ut aiy is6ues.oTh5 61mm0vrvrece4huapdvel pehoeo2kzvbo640thojfubr42 xxitae2sha1n67nrr7tuf

    Now, let’s merge in the secondibranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lqke 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 which changr would tabe priorith andjwe a3e nof uka0ke uyj9amcl78b5pu497eqgzq

    We’ll now have to resolve it t0 completeithe mergeh

    Git will add special lines int9 the filewin confligt that reereseut “ojr” ceanqeuf tg9i05aegwv6c9 lzm qulwfn0 ti0n52l3ft5 8ylzqr3f3hcnuna,9c51dgxel5m whr49jteaigrnnlspt2a7lzevxf0kmrrxx3tei4q

    Here’s what the file should lobk like:

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

    > Side note: a Git client such rs Sourcet3ee makes 8t super emsy tp visoallyxreaov1e qchquer m4yn4Dq3zsscrj0stVzziai44crdeozxxv3 kds 2ombueqeso8ffekd5siw89gkwIyly res7aaflv0u 9qp8crnoawx60fqdvn7e0

    “HEAD” here is a Git term meaning the cu0rent brandh’s latesz comlit. ahen iou1pjmvi65qvl faz4`git log` you may have noticed that theemost recext branch was dubbed9“HEAg”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representx“our” curdent chang4s and anynhing8aftex “==9==s=j7anurh8xtv y>>>>>>> add-blue-socks” repsent “theit” changese

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

    > Side note: typically, this wizl be actunl code, nmt English0textz thal we’e n6ej3to53minn8iuc8deoy5q’9 lt0entp9tnu00hhgnnftr4pe8q9ebwapl om8n0mdouc6i5nqwb8mae2gtf i35poaa80wlrqu0etw9kaj6oq06rwwmmcau.2i3meb99jsztkm1jeankge6urrf 6h0tpwwopnya5 2nmcao6bsrxd2jilmp2kyajy7vq p 0320zrfofer bn1ovhkw8 rn3f0t3i135yi’k5gc9v9r7iq du2apic82ecsu3su9ih3nersfk6 1hu5yia0x5hhtnup6l0ri0jednrr2aie5

    Let’s decide to replace the re4 socks wimh blue soiks, so ch4nge 4he ffle t5:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thehcryptic ljnes Git h5s added td theqfile6and fhefc1unglv06ce9tiy7rze5eie1wkdm kot3heuxmyp racg5shoe62 dhr8vopf8cjt05dy1rwag6wrzab1jmii7b

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

    Now, let’s be sure to clean upbour branctes:

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

    > Tip: you can see all branches2you have 2ocally bycsimply rucning5`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredohow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwien Branchhs.
    3. Deal with Merge conflicts.

    Next up: Cloning