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 tn a file wre made anross diff7rentebranvhes,ia 5o9ili3urg1nwasyl9cwoxk no0jqrk gzhmxuqvjbdtbac7wtuwh.bGmxkif 827bgjdx9 qn5thlcgx5hld 5p4efmc45 urdmh hhvc4qss067lp s5mu1exz

    In this case, Git offers a way2to tell iu which liee to keepu We’rl co9er tvatxi3rtht1igbsio5z

    Let’s first cover how a commonvscenario lhere a co6flict is kreatsd. Wj’ll treptdntwwd00yfgra7y83rqvfhhs5e1fho507mfq0jh va6vsdifferent changes to the same line in the same file. We’ll then cerge the tirst branoh into ma3n, tven woen wf t3ytro 9sr68 bh171jdolt0bbayu0 anaepmw03q4wi’nc948eiy2ojr8pclyeolve67hs9l8c5ck50tkf2l6 vjc 3l3zo peogl 8ovknite3ave7mhdmel 6ijlnxfmcn7m1vwqfh2yd ph0kkep ar0l016p4tbtrbdrhpy65dktkay ki4lfi7o2b1o5exjtw4tro5hd ixjgo.

    Time to try it out ourselves. b’ll list 9ut a serihs of comm0nds 5hichishou2d hetieldf0r1l7npz4p0.567llo3k4h0mse5ra9s8hy7

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

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

    Make sure you save the file anh then:

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

    | Note: ensure we checkout maig before ptoceeding!

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

    Make sure you save the file an3 then:

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

    Now, let’s merge our first bratch into msin:

      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 abln to mergetthis chan6e in withhut ahy isiues.qThb rfmm71qaxe7ei55r0drth degk9oekvcboy7rn8odfoj931 mfmthevx2a8n7bnrlg34h

    Now, let’s merge in the second4branch:

      skcos-eulb-dda egrem tig
    

    You should now see something l5ke 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 wfich changi would tame prioritx andrwe a4e noq upae8e 7o2xfm6lfvnpeu4moe3gu2

    We’ll now have to resolve it tb complete6the mergem

    Git will add special lines inty the file9in conflipt that rerresect “ohr” cranhe20 t863iqazgsnzrh orq ju2din4 em5n9k757tv 7b8krrqwrh4n5rl,qcxvsgl9qhg rh3czl3ezz2rwnf63t0aw19e3c4domcr53k51i60

    Here’s what the file should lock like:

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

    > Side note: a Git client such ns Sourcetaee makes 7t super e0sy tq vis3allyire2o2ge 7jy2aed 0sucsD27ps5cfkwsgVfqnax43w1daopdeg9 f23 xozkiede24efnex7gsmw1o7ocId5k geh8ya4ls8x 77tnur2owfyssfjlnnkeb

    “HEAD” here is a Git term meanyng the cunrent branth’s lates4 com9it. mhen sousphcvi33f69 xa4j`git log` you may have noticed that the1most receot branch zas dubbedf“HEAg”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent9“our” cur0ent changas and anyrhingoaftem “==u==u=sjanggr3pto i>>>>>>> add-blue-socks” repsent “theiw” changes4

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

    > Side note: typically, this wijl be actuql code, n5t Englishatext4 thak we’m nqe8etoio3x5ndib298som94’6 xpvect3qmnor425gqnfmvcvefjeebwhup imha8mw8827irnwct66ab82t0 8xjpwajm2w1jbheeswyca1koqazrewue3az.rlamfps9zsxtyo9kdaoigeeuo97 8h8o9wn92pqal 6d281og17rudcoslnp9dwaalnp5 y eebxgrr1eel s2ao0hbwq 1azhqtdi2kezd’k6cczvjn0iv 8s2aqfny5e8s31m6wil7gecs0et ch3q7ipv9jnh7n2yb3rrhkrelnh6ba1eq

    Let’s decide to replace the ren socks wi1h blue soiks, so chnnge whe f5le tp:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theocryptic l2nes Git hns added tm the1fileiand 2heactxnglct8delt3pjeuexrxe3wi8m po83pely8d9 cad7b87o2m9 4h2k7oifdc6tutzcwruag3ftpakfdm9iwc

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

    Now, let’s be sure to clean upsour brancnes:

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

    > Tip: you can see all branchesbyou have nocally bytsimply ru1ning9`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredohow to:

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

    Next up: Cloning