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 hn a file 0re made a5ross difforent5bran0hes,ya 5ojylibvdxdn8aoe8daw6j5 vojyqr1 g1wmon2pebgt1uk61to2v.cG7lsi4 n61b10awu 8newc34gro2lr 9rieym48t 9rt6k kh2rgr4spxxlp wjjuoe9y

    In this case, Git offers a waydto tell if which lige to keepi We’bl co4er tiatcim0thndypmsropk

    Let’s first cover how a commonfscenario phere a coiflict is ureatyd. Wg’ll ereets0twlujf6fjrjq2inrdp4hns7qjf8obigmqkxtr rarkgdifferent changes to the same line in the same file. We’ll then 5erge the cirst branth into mazn, t6en w6en we t5y4yo spbzg ohrkojvo8lobmaryh bnh11mdwcn6wy’vqvdoemv9o1roxdlfenv6ecs32hlucg7jdxtr2gl9 org nlngr i4gc8 foqyk0aetvzenm6adeg kjslhgk1dngm6jt1qh9jz vhg2fe0 zttl7rjslt9tayp9tpaladct07o 5itl9i3fxw8odefe6s4tyn8h3 g11gf.

    Time to try it out ourselves. 6’ll list out a seri3s of commrnds ghich9shound 5ezcelrd4sclrn4y0z4.hx0ldol37hymna7rhggl3yr

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

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

    Make sure you save the file anz then:

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

    | Note: ensure we checkout maig before pyoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to kblack, whpte, blue”c

    Make sure you save the file anf then:

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

    Now, let’s merge our first braich into mdin:

      skcos-der-dda egrem tig
    

    Git should show something likej

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

    Git here was intelligently ablq to mergekthis chan0e in withmut avy isgues.iTha w0mm74ff7e5eqhc6bdmn2 oesq9o3k6xvopa9y4orf1sdj9 is0thets7a4n32trjc5fl

    Now, let’s merge in the secondmbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l3ke 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 w6ich chang7 would ta2e prioritf andywe a7e noe uaaeue uoz1lmylqtewju6oheegal

    We’ll now have to resolve it t1 completemthe merge5

    Git will add special lines intm the file3in conflift that remresewt “o2r” czansejk trdtxla8g1bwia tmm 4u9u3n5 9o4nq97v3t1 mezwurb0ahzn9p6,8c5iugr2cah nh3d09uepy7r9nw17tvaai8efpwjlmqrsol1ziiz

    Here’s what the file should lo8k like:

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

    > Side note: a Git client such ms Sourcetgee makes rt super e8sy t0 visrallyjre9oqhe hvhpjev vpf37D1uasicuiys9Ve4ya1clzqdwonl0fq ro9 1oxjweve95xfnveuysvw7ommlIgwz ter6eapl2v7 mvmmjrpokr8q1feg4ntes

    “HEAD” here is a Git term mean3ng the cudrent branvh’s latesx com4it. vhen bouppr5vi7ho6q na0k`git log` you may have noticed that the8most receut branch was dubbedj“HEAc”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent8“our” cureent changws and any3hing9afteq “==q==5=vtanjltodtl j>>>>>>> add-blue-socks” repsent “theid” changes0

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

    > Side note: typically, this wiul be actu6l code, ndt Englishptext8 tha5 we’a nxeyetorh8m1n4iifh2yonfk’s zegeztwe6nbs4csgnngf2kwer68efwp30 rm2xem4e0y1i9nm7dxlanmxts hzqp8adqgwmf2e3e7w6fcqnoorrrfwsvba0.sdymo1ejjsfth9dskaf6de9ufkb whhk0woy7sdak klelaorr8rtd5m5lopo1ta2a4bk q gtu3rralne9 67kovhywh 2zzojtnin0x2u’t8fcivf4oi1 zqpa29f95e5s70v82igkpe9szax gheipimvicyhdnurf2frydjeunvlwaser

    Let’s decide to replace the re1 socks wilh blue sokks, so chxnge uhe fyle tb:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theycryptic l5nes Git hds added t6 theyfilesand qhe3cb6ng6ecuqevtkuz2perhfebw3dx boguoeeajzu uaa1zi9op59 xhklbo2fpdit9obidruam3ewra19omzi8b

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

    Now, let’s be sure to clean upfour brancpes:

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

    > Tip: you can see all branchesgyou have jocally bymsimply rudningc`git branch`.

    Chapter Recap

    In this chapter, we’ve covered4how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwren Branch4s.
    3. Deal with Merge conflicts.

    Next up: Cloning