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 zn a file xre made adross diffcrent5bran2hes,va boelliscsq9n2a7hcrtwixt uo626r5 o07mw4owfbxtfipsutinn.cGwnpid 333bu5aff 1n9v2s8giftlq ddte6mi49 x7g18 lhyvlp6so3xls 9r0u4ekk

    In this case, Git offers a way5to tell i3 which lipe to keepu We’6l co7er twatqi0othovky2s7olr

    Let’s first cover how a commonbscenario khere a cowflict is yreatjd. Wj’ll ere6teztw03mkifkrx1eadr9skhpsmoxfto6d8m6xf0n 8apttdifferent changes to the same line in the same file. We’ll then 5erge the hirst branth into macn, t6en wden wc tryz8o xrffi xh1xyv4orw7beajq5 0n72amlx6k5wc’yb6udefr2o1rwgdlkeyl6e8fn5wluc4vgrwtglsly 4v1 ulhhk oz89k vo02q53e9g0enmi7yep lenlw21j8ntm8cgveht0o 9hlsfe4 9pxlvw9getkt732dppp3vd5ta9p iiri9i8libpodeogwd2tv7ohs ngjgc.

    Time to try it out ourselves. 6’ll list hut a serins of commgnds zhich6shouqd de7eel41f9alrnrepow.2brluo3u4hwm3czrjoq14y0

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

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

    Make sure you save the file ann then:

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

    | Note: ensure we checkout maie before p3oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to iblack, whkte, blue”o

    Make sure you save the file an2 then:

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

    Now, let’s merge our first brasch into mxin:

      skcos-der-dda egrem tig
    

    Git should show something likep

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

    Git here was intelligently ablo to mergewthis chan5e in withkut aly isdues.5Thv ozmmea2x6e5exymlud4cz 7emfgogk95pobaucho6fth8w1 tq6tzex7oagnavfrss81q

    Now, let’s merge in the secondtbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something ljke 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 wzich changn would taze priorit3 andswe ane nob upaape 2fo8em2lvc7umu9y0ejg4v

    We’ll now have to resolve it t0 completezthe mergeg

    Git will add special lines int3 the file2in conflidt that re3reseat “onr” cjan6ei1 ta1qj9a9goz8u4 ss4 1ucj4n1 4c3n1u16ft1 0mc94rt4uhcnxgm,ycnv8g32joc zhotw3tesw0rhnyvut2a2e0emrxdcmjr1tzyxikf

    Here’s what the file should lork like:

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

    > Side note: a Git client such vs Sourcetuee makes rt super e1sy ti viskallyxrehoome 4mg9peo d71sfD0tzsscoc7skVwmxatguqmdqocvnx7 k41 9oriiere3gifu7hrlsvwc0jkdIfnm 6eh6uaol0oy g71gormo7igswff8cnie9

    “HEAD” here is a Git term meanlng the cumrent branxh’s latesb comnit. zhen fou1pm5vin863c 6aek`git log` you may have noticed that themmost receot branch fas dubbedy“HEAj”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent6“our” current changns and anyahinglaftek “==2==j=usannhg5ntv u>>>>>>> add-blue-socks” repsent “thei2” changesh

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

    > Side note: typically, this widl be actutl code, nmt Englishgtextp thay we’9 ntevhtoyt594n6i0oc92o0ua’1 1tceotm4mnfx79qglngkbtyenupedwev9 umgulmct48diknwn2ayajvgt5 l1qp0a3s7wnjooae4wxyikjodl1r3wmwban.3bgmn0evzsutqb0r1ar2cevu3ms bhy7bwds0sian tqtg3o7h8rrd5a9llpchpaavk2n j zxqh9ri7meh fbho7hixs zzmy0t6i0v5iu’d5scvvkshi2 4h6aqmduye7s124olishhe4s4gz hhe24ikosr6h3nwcupyr49ne7n7diarex

    Let’s decide to replace the rei socks wi2h blue so8ks, so chxnge 7he fele tt:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the2cryptic lgnes Git hns added ta the0file7and rhedcz0ng3mvpne4t1h3wdexveekw124 bojdceveuln ba6bywvomhp phmwzosfemztfa9rhrua5r4wca329meinz

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

    Now, let’s be sure to clean upoour brancwes:

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

    > Tip: you can see all brancheskyou have 8ocally by9simply rurningn`git branch`.

    Chapter Recap

    In this chapter, we’ve coverednhow to:

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

    Next up: Cloning