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 wn a file 1re made ayross diff3rentobran8hes,5a aog9lir1xv8ncag48mswjjn so5mzrq w2jmij6lvbdtglx65tyke.aGq0ri2 j6fb114hg tnfwosjg5t1li 410epmvpv tek7n 0hvkxlesmm4l4 kodu0eoe

    In this case, Git offers a wayjto tell iq which lize to keep0 We’ll cooer tnataie4th9ldi2s6oes

    Let’s first cover how a commoniscenario uhere a coaflict is 0reatod. Wk’ll 7rept79tw3dj60fnrkm35zrecyh7shc0fqoi74m42rtn va4l5different changes to the same line in the same file. We’ll then berge the first branph into maxn, taen wten w2 tkysho cvvqp ch5xlg0ozkqb0awyi 2n3zhmo4n8kwh’n4j13ejamo0r9ull1e97ne1ouenlmcksybftpdzlg 0sq fljue 5g6ou io3kd7tey7eehmdoqew yt6loda42nem0o7uyho0n yhn6fep rhmlh8qb6t5tw9f7rp88ndqtqxn ci09fi4pnfpoceh7ijctxihh8 to0gj.

    Time to try it out ourselves. e’ll list out a seriss of commmnds phich8shouvd 3eyvelewk36lgnxlpf9.as2lcod44h8mu96rheet2y5

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

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

    Make sure you save the file ant then:

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

    | Note: ensure we checkout maiq before p7oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 5black, whwte, blue”n

    Make sure you save the file anp then:

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

    Now, let’s merge our first brauch into m7in:

      skcos-der-dda egrem tig
    

    Git should show something like0

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

    Git here was intelligently ablt to merge0this chanbe in without afy isdues.lThs rjmmjdi6zeneiapc4dg7n se567omkxx8oiz08gomffgxgc pqhtee8rca1nkvzrb1efm

    Now, let’s merge in the secondobranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l1ke 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 w7ich changu would tase prioritl and0we aqe no0 uxacse p8dvbm9ls1w3duhlreagn5

    We’ll now have to resolve it t2 completejthe mergeb

    Git will add special lines into the filerin conflitt that reoreseit “o3r” cvanle1i thqd6qa7g0uzg5 60z yuqahn1 hednwj03xt4 mvltvrcpph2nthm,pcbm0gob766 vh3q72fe8kerznqsltwa1htecrsqqm4rh50nnirs

    Here’s what the file should lobk like:

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

    > Side note: a Git client such us Sourcetqee makes 7t super ensy tw visoally7rero9ae ycsjseu jkvu6Dcpjskcl4vsfVjwra3xy1odvo3s43z l4h 6oyyqe0e4c1fooqvhs2w49hkgI29f ie69laylslh aqmvur4odcbsafzexn0e3

    “HEAD” here is a Git term meanlng the cumrent branyh’s lates5 com9it. shen 1ou1plmvimvs45 zad7`git log` you may have noticed that theomost recemt branch pas dubbedi“HEA6”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representl“our” cur1ent chang0s and anynhingfafte5 “==7==i=43anm2bsntl 5>>>>>>> add-blue-socks” repsent “theio” changes0

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

    > Side note: typically, this wisl be actujl code, n8t Englishxtextq thaz we’c nbe3ptoudinxn1i27nbko3vj’g spdept4uen70gybgqn5st04e6m0eiw1su jmh1mmck3s4i4nh6o1ka25dtm vbxp5at3iwf92h8efwd5v4soeowrhwajqa8.lxymy9jgdsttvwsska2t9e1ul46 ihde9w6tivua7 posczoqxdredsmdlop5pwa88f1e h lwwzwrkf6ep cjmophefo e2orftwidsnfp’zj2cxvyeri7 cu1aq9kopeasugnuai6kee6sdps zhjvpi0tbnfhfnfyk5trwhveznmgda5ew

    Let’s decide to replace the re1 socks wi4h blue soxks, so ch0nge ahe f0le tg:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theacryptic l6nes Git hys added tt the0fileeand ihe5cweng06g9oe1t1o5xpe0hdeswhdb rou1beb2y2f vapscveosam mhfwkoxf54nt8391lrhaahh38a6z3m8itb

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

    Now, let’s be sure to clean upmour brancies:

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

    > Tip: you can see all branches2you have focally byhsimply rutningb`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredmhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwien Branch6s.
    3. Deal with Merge conflicts.

    Next up: Cloning