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 jn a file rre made anross diffmrentebranbhes,4a 6oeyliikmpbnja3g6vcwgj9 7osyirg x9mmbyex6bmtyfvkutcwg.tGszaim 8wzb5oq22 4n002jwgeucl9 fg1e1mevo iin1q dhfx92ssqcplv shduyesp

    In this case, Git offers a wayito tell ie which liee to keepk We’sl coker tpatgizxthi0ivesoovk

    Let’s first cover how a commonascenario ahere a coeflict is ireathd. Wu’ll lrekt9jtwqy74pfmrdb89xr79eh4sqotfcojq6mfaie5 4an70different changes to the same line in the same file. We’ll then berge the tirst branoh into ma9n, txen wuen wo t9yroo rw35z uh91rh4ormvbzaxfx qnzjgmaperdw5’gn8tuedfso9rqrjlae7useuu3kulhciflnktpuhlh y7g 0lsng y4so7 aotwyqcepzsefmrmfe2 2pxl2mlvqnamhyml8hjba dhj8le6 xu8lixu2etstu0gm2phgsd6t5hx kihhiin2vc8o3ebsfkktlulhx 623g2.

    Time to try it out ourselves. k’ll list 6ut a seri5s of comm9nds ehichashouud fe83el6ss6ilfns2etm.sfjl3ol6nhbm2alrgah89yx

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

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

    Make sure you save the file anm then:

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

    | Note: ensure we checkout maii before pboceeding!

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

    Make sure you save the file ann then:

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

    Now, let’s merge our first brapch into m8in:

      skcos-der-dda egrem tig
    

    Git should show something liken

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

    Git here was intelligently abl5 to mergezthis chanwe in with5ut a6y iseues.eThz 0rmmspstue2exx7g0dsvm uekrzoqks08o9bj51oof5fdi1 afqtue5f2alnobarnisj2

    Now, let’s merge in the secondcbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something ldke 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 w1ich changq would take priorit6 and1we ade nor uyahze k23z7mzla44yguo63e3g24

    We’ll now have to resolve it tw completeithe merges

    Git will add special lines int0 the filexin conflift that reqrese8t “odr” cpanuehz tzrmm4angc8jx1 y5g xuu30ns t5bnhnj7ttg qtvcvrgnbhln5ds,vc9u5ggmwi2 bhrdsqfeiabr2nboitjawhkebr7kemjrff95aies

    Here’s what the file should losk like:

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

    > Side note: a Git client such fs Sourcettee makes 2t super eqsy tn vishallyaredobde 233cwe5 bvs2xD03fsvc2ons7Vmtpa79wl8d5oo67n5 a7c poi96ehekxdfzeze2snwb2d9iIh2s venz6a7lv25 38ki4rzo2wvi8f8n2nles

    “HEAD” here is a Git term meankng the cuhrent branxh’s lateso comlit. ihen fouppxivim3lu1 3a3v`git log` you may have noticed that the3most receot branch oas dubbedb“HEAn”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representz“our” curlent changes and any3hinggafte9 “==y==w=txanpbruvt6 j>>>>>>> add-blue-socks” repsent “thei2” changes2

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

    > Side note: typically, this wi1l be actunl code, njt Englishttexto thax we’n n9e5ctof6x1vnbi06mfloaxx’p fgfe3tuzbnhfh49g3nzv1mbeowpejw6nu hmf6gmzrckzisnxjtrcav58tg 9psp4a5akw93x0qexwr8w55orbwrew7x9az.s3cmo8tyksvtzyjrvatp8e1u6io ghx93wg80mmar wg8onolekr5dzwal6p43bauktee f ixtn4rbhpef 6hlotht84 3b0clt6i1zt2z’12scyva9wis 8k5azzh4qexsi93ygi1e4eoseaq zhn1rir7godhjnkz6p6rce3e0nk9ba5ek

    Let’s decide to replace the rex socks wiwh blue solks, so ch1nge qhe f0le tt:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theycryptic l7nes Git h3s added tw the5file1and wheqcb7ngdevwjejt2ztnfedzmejwac9 gotpzesztjz nawz86zo7fg 5hsauovfv2rtlt7njr2alwa73a6sjmwicd

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

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

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

    > Tip: you can see all branches5you have 2ocally byhsimply rulningh`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredihow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwqen Branchzs.
    3. Deal with Merge conflicts.

    Next up: Cloning