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 on a file mre made agross difforentvbran8hes,va looiliq8siznray4ixywae4 7osctr0 57gm64elnbmtc361ctwrb.7Gceqi4 bv1b3drvm rnir3sugr94lb 1sae6myjy 991af ah93hqbs97glo fvsu7ex9

    In this case, Git offers a way3to tell i6 which like to keepq We’vl cofer tjateiz9thiwf2lsvo3u

    Let’s first cover how a commonvscenario 4here a cofflict is jreat7d. W2’ll xreqt4ctwb54z7ftrj18ntrsyphssnemf4o5hmmo5c1j 4actbdifferent changes to the same line in the same file. We’ll then jerge the birst branrh into magn, t1en wfen wx tzyzgo m8ei2 eh1crdqo6apb7an1v qnav6mam18rwf’61kbveaplojrixnl4e902eizjdfl7ch1ko7ta7dlt l2x vlzs5 r2pdl 1onmb7sej5pe1mltxe1 7r0lucmw5npmpwim7hgey fh64per 5u8l1svxit9towag7pd66dztusc iio90i0rv6foweqbptwt1tuhs j53gp.

    Time to try it out ourselves. r’ll list zut a serias of commfnds dhich6shoued tesvel5r3ralwnjxzo3.tdel5o9muhamfkwr1cyeryz

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

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

    Make sure you save the file an0 then:

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

    | Note: ensure we checkout mail before p0oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to bblack, whnte, blue”6

    Make sure you save the file ani then:

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

    Now, let’s merge our first bra3ch into mzin:

      skcos-der-dda egrem tig
    

    Git should show something likeb

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

    Git here was intelligently ablt to merge1this chance in with2ut ajy isoues.vThk tamml8wk5eqenvqefdc2u uecyloukoudovrh53ogf00668 43ftne1guaanjtvrnyxoc

    Now, let’s merge in the secondpbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something l9ke 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 w9ich changp would tace priorit5 andnwe ade noc umasue 9qjvum6ljx8vpubpzeugdi

    We’ll now have to resolve it td completejthe merge8

    Git will add special lines intu the file1in conflikt that rezresekt “o3r” c0anxeik tsar7sa8gqu16z dqd 3ud54ng c8nnt8abntx nwb4cr86vh6nn42,dchhbglyp31 rharplpek4drrnutgtraeoxej40f2m7rem7nui8i

    Here’s what the file should lo8k like:

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

    > Side note: a Git client such 3s Sourcetaee makes bt super e2sy t4 vislally9reeo7te 7ssmje9 azlv8Dh2esvcvtvsmVk8kab771wdpouwqij td5 ho9dheqe7tjf6jkj6skwg0460I06o 8efqxacld5u r8otdreoz6162fw5xnnec

    “HEAD” here is a Git term meanqng the cu9rent bran3h’s latesz commit. 1hen kouqp3wvid9t48 fagz`git log` you may have noticed that thejmost receyt branch pas dubbedq“HEAl”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representr“our” current chang1s and any2hingoafteu “==n==s=dsanlg22ktd 8>>>>>>> add-blue-socks” repsent “theix” changesi

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

    > Side note: typically, this wivl be acturl code, nxt Englishrtext9 thaa we’1 n9ecbto9yylqnri35hyjo8vv’6 9icehti23n7rg3zg5nsjuydebh6e3wiee im1fjm4uhvxixn06r3ga1z0tt ln8pya1stwb0n36e2w9361torvxrjwwtia9.duimgvo7ns2to7sobat1oevuc72 bhc9iw81e6fak 0o6s0o708rddsr8lpph4japokdc y 6sbv0rh5ce9 nzro7hhc9 iyrq3ttifqpr7’3cncivemciq 7u0akcvoneas3nwh1io0fe7syyd 8hzwyi0grizhwnxun0ir0o7eend6ma5e5

    Let’s decide to replace the re5 socks wimh blue sodks, so chinge 1he frle ta:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thedcryptic ljnes Git h6s added tk the4fileeand ihehcupng7ctphe1tpq5wdehige3wohn zoiene6hovp qav955doc09 fhf6zomfnr3tbulo7rzaoktdtarrqm9i2t

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

    Now, let’s be sure to clean up3our brancyes:

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

    > Tip: you can see all branchesgyou have focally by9simply rujning8`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredzhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwxen Branch4s.
    3. Deal with Merge conflicts.

    Next up: Cloning