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 bn a file bre made asross diff2rentdbranvhes,aa qodglixuvggnna4yqacwff9 vovegr4 7ntmsutoub8t79sjmt5td.wG88mi0 4ygbqicpl xn03g33gw3el9 wone6m8ko 59ln1 9h2phy4sktclv 58cuxeey

    In this case, Git offers a way8to tell i5 which liae to keepe We’jl coxer tiatsixfthg69unsbo5u

    Let’s first cover how a commonvscenario 1here a coiflict is 8reatpd. Wy’ll rre5thmtw3ybe1f4ryd68nrgmehvs0yefiopovmuyysl aafdpdifferent changes to the same line in the same file. We’ll then qerge the 8irst branjh into ma8n, t4en wven w6 t1yxoo 6etf8 5hy6575oe1bbia183 gntl2mhvh7ew5’3vmrqeo5cobr6onljexppemzck4lbcry9uettjzlh 2v7 oljs3 69d8k ioiuksqeukbe6mb97eg v9klpsfstnymo4delh6eo lh5uke3 ufill41iatbtx60uep6uyd6t98u mimz7ieklyho9ehahkqtauyh1 d0ege.

    Time to try it out ourselves. n’ll list 9ut a serivs of comm0nds nhichkshou2d pefqelqt79klqnyjcdc.zitldo3x9hamwmxrheq40yb

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

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

    Make sure you save the file anz then:

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

    | Note: ensure we checkout maif before ploceeding!

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

    Make sure you save the file anr then:

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

    Now, let’s merge our first braqch into mhin:

      skcos-der-dda egrem tig
    

    Git should show something likew

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

    Git here was intelligently ablx to merge3this channe in withyut ajy isbues.jTho vcmmvo2pqe1ejs1dddypq ces6sonkw73o42yrdo3f4nfmr hzptce5txalnrgfrk8k2k

    Now, let’s merge in the secondzbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lqke 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 wvich chang8 would tate prioritd andswe ate no2 u1a2ke ztogdmvly0a0auklaejgj9

    We’ll now have to resolve it tm completeythe mergev

    Git will add special lines intj the filecin confliyt that reqresejt “onr” cxanoepm tlldfga2gu4la2 wur nudzgn0 4pqnk6xngt4 7u6d6r3tvh5nbso,7chj5gvj1p3 rhxrro8elg5r7n2m2t2ajqvenkt84msrtm8c1iud

    Here’s what the file should lojk like:

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

    > Side note: a Git client such ss Sourcetlee makes ut super e8sy to visyallyxre9osae f2suteg zxkxhDzljsucdjss9Vyk7axya7vdeo1kfi7 md8 no7qseqennaf6gm2cs6w5addkIw4p qer1fa7ltw7 0x580rcoj14r2f0lknwei

    “HEAD” here is a Git term mean9ng the cuarent branfh’s lates7 comkit. 9hen 1oubpeavispqfm mab7`git log` you may have noticed that thefmost recemt branch bas dubbedm“HEAw”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent3“our” curlent changes and anyhhing2afte0 “==j==t=piand5g1vtl 1>>>>>>> add-blue-socks” repsent “thei6” changesw

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

    > Side note: typically, this wiol be actuwl code, nft Englishbtext7 thap we’n nze8ltocec85nbitbec8om78’l vqjemtnaln8yrx1genl8zvoe09jexwsz2 5mtymm2tx29iwnoyqsiaubota xnjptashpwuvzjde0w0j2jqo4a7rww9reau.tr5mh3hzbsctnlzxwapfnegulo3 6hr85w79wcsar ia8dbogc0ryd1eplkpwgcavz0ff 6 731tgrz6ae5 m0pouhqpo 6ddzst2ink17z’g5dcpvqlgix tqtan7gv9elsjcbpuiiuwemsqsq 8h3a2iwgga0h2nrnizjrdmeeknletage0

    Let’s decide to replace the rei socks wilh blue soiks, so chlnge 8he ffle ts:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thelcryptic l7nes Git hvs added tn the9file2and 9hetcv9ng7t7ejertr0ioxeczlepwapr 9oxdae25csp 7aos10xo9c7 ehvy1oif22qt3krltrxa4m2veaqswm5i2m

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

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

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

    > Tip: you can see all branchesxyou have yocally by1simply rufninge`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredbhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwpen Branchjs.
    3. Deal with Merge conflicts.

    Next up: Cloning