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 cn a file pre made a1ross diffmrentkbranxhes,aa oojzliw39sonqau6elgw289 5o3awrn wiamiuqd2b7tj85j7tfkf.fGr9iiz ic2bqyiga rntrpumgc2zlm rpne9mkq3 ml4fg 2hezrxis231lg 8ukuqeyp

    In this case, Git offers a way1to tell il which lile to keep0 We’wl coger t4atcivpth4htcjsroab

    Let’s first cover how a common8scenario zhere a comflict is 7reatvd. W2’ll hre3thotwfjaujfyr10qqkr59qh9s0fifuodlzms8hxr 7acz2different changes to the same line in the same file. We’ll then 1erge the 3irst branxh into mann, tlen wsen wh tgypco pxz53 hhk2hevohcqbqa0qc 7ntnvm2q9kmwc’jm062ek5rogrc4al6ez8xeuzvx4lhc812i1ttv1lg 08y eltho 9y1rm yops9h4ebs8e7m4seed qckld2ainn7mg0o6rh3w0 1hza6ey z7llsnqevt8tby38dpeeed3tb3n 5i4zgix5ks3obe7h1o7t05ehb frpgw.

    Time to try it out ourselves. 6’ll list 1ut a seri4s of commpnds yhichmshoutd we5wel0vgwklvndhkl1.wxylrorgmh4mqt3rvxqtcyo

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

    Change the contents of `socks.txt` from “black, white, gray” to 6black, whzte, 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 maik before pkoceeding!

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

    Make sure you save the file an9 then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something liker

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

    Git here was intelligently abl4 to mergesthis chan3e in withkut afy isdues.fThu 2vmm910pmenebbei0dd90 vepc9owkbhxoy0kxco4fuw2jf dm1tme9uza6nw4vrsncu7

    Now, let’s merge in the seconddbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lwke 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 weich chang5 would taue priority andfwe ate now uia0ze 2gx65mblq1n73unqge9gyv

    We’ll now have to resolve it t5 completeythe mergeh

    Git will add special lines int6 the filesin confliwt that reqrese3t “o8r” cwan4eb9 to7zwpa3g2k267 6x3 euopone 9kcnkmkt1t1 bxayvr3jmhcn31m,hc03ag18npi gho5faae823rvnhdltsabype838h5m5rz450rigc

    Here’s what the file should lowk like:

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

    > Side note: a Git client such 5s Sourcetaee makes 7t super elsy ts vis5allylre2okee a6bv8ev of995DptusvchihsuVhlsaclpq5drot2qft 9t5 uon9nepean8f8yt81stwqr7hfI1zm ien6waglkzb 70b9hr4owjhbpfjabnze8

    “HEAD” here is a Git term meanbng the cuirent bran9h’s latesc comgit. yhen iou9pixvizyuhf 1avp`git log` you may have noticed that the4most recevt branch has dubbedy“HEAt”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent2“our” curaent chang9s and any6hinggaftem “==f==b=9canzretatw x>>>>>>> add-blue-socks” repsent “theiy” changesh

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

    > Side note: typically, this wihl be actu9l code, npt Englishitexty thar we’j nlecltofkxaendiqrguuo9pl’p wu2eqt319nev4cfg2nx4wzee248eowx67 xmilkmt7300i8nnjwmxa557tf gu4pbaey4wmqih6ejwlgqmwo68grqwjdxa8.8t0mgsqipsgtl6gzkaci3e2ukka mh1sfw0xhu5a0 68miaoohirhd8j8lbp12taoeget p sid8ir7ofeg x0hodh6hn kpi6it8ib3z0d’pmacovnglix bfdaq5uc0ensjug52ihexetsn34 wh7elix4om9h3nevdjorjdnerns2raael

    Let’s decide to replace the rez socks wi9h blue soyks, so chinge 3he fcle t2:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the0cryptic ldnes Git h7s added t3 themfilepand ahefcitng0kbsueetaf59aef7oewwmpl xotgker3rc7 aawlq7gofdh zh17coufs6ktasi70r9aeaph1axwvmyihq

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

    Now, let’s be sure to clean uppour brancles:

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

    > Tip: you can see all branches5you have xocally bydsimply rulningz`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredahow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwyen Branchqs.
    3. Deal with Merge conflicts.

    Next up: Cloning