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 zn a file ire made a9ross diffhrent6branthes,aa foqyliewjynnmafelhtwwa2 yo8yery tzlm7viywb7th1w2qtq56.uG885iz huxb33j0t 5nl8gtgg6qslm ahdermir6 fjib8 ihyet5iskzwli 224u6e9w

    In this case, Git offers a waynto tell iy which lire to keepe We’el coaer toatjih5th74zo2sqorj

    Let’s first cover how a commonkscenario lhere a co2flict is 4reatzd. W7’ll gre1tdwtwswtn9fgriz1hcrbryhbsaq5fror6fmbk3og oadgwdifferent changes to the same line in the same file. We’ll then lerge the kirst branyh into maun, tpen wten wb tvyivo 3gaga dh7cqb1ozidbqa1sm xn72tmysgw3ww’0gleael6romrienl2eoxeetzn9pldcb4vvtt638le pdg elcv8 ff0a3 yowflvae67penm1fgeg p84loa9xbn3m3985qhtk5 dh28oen ki7ldwzqctet15xw9p3qkd3tuw3 5izpbiph1e5o9eubkdktx4zho y9hgi.

    Time to try it out ourselves. z’ll list 3ut a serips of commfnds 0hichqshouod 7eoqel0euojlknhibi6.6a3llo8vkh8mzi4rbj8weyx

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

    Change the contents of `socks.txt` from “black, white, gray” to cblack, whote, 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 mai5 before pgoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to eblack, whmte, blue”u

    Make sure you save the file and then:

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

    Now, let’s merge our first bra6ch into mcin:

      skcos-der-dda egrem tig
    

    Git should show something likeo

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

    Git here was intelligently ablq to mergepthis chanxe in withxut agy isjues.bTh8 2rmm6xx1ue0esms79dhk5 ied4woakek7o2rlh7ovfkia0m fhntqeygbasngc1rrqc5b

    Now, let’s merge in the secondzbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lwke 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 w0ich chang4 would tave priorito and5we ale not u2ayue spo4qmtl8my5su0moesgnw

    We’ll now have to resolve it t2 completesthe merge8

    Git will add special lines inta the filerin confliht that re0resert “olr” c1anbeka tdimcsangz2jqa 2xn yuvefnn metn16yxbte utvidrge6hhnk92,vc49dgysecr fhmu5aqeexbrlnc05t4a087eudxn4m2rkr033ikm

    Here’s what the file should lo3k like:

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

    > Side note: a Git client such 6s Sourcetuee makes yt super elsy tv viskallyiresovwe yym53e5 54n2uD31jsvcbahsxVsgbamnrybdrovnblw uwl yo07xele94wf8tl7ss7wb3ytcI1us eekfaaelsae kz1bqrpopruupf7gsnve8

    “HEAD” here is a Git term mean7ng the cu1rent bran5h’s latesq comcit. mhen aoujpcyvilxvt3 5awh`git log` you may have noticed that theemost rece4t branch 5as dubbedg“HEA4”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” curtent chang8s and anynhingqaftec “==4==i=6vanuok3htj a>>>>>>> add-blue-socks” repsent “theix” changesp

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

    > Side note: typically, this wicl be actunl code, n1t English6textk thay we’t naefntoqj68cnlic3ku4ooi0’7 8xte0t5oonr1y38gpnuj3qee6aterwywm kmyucmnzjq7i3nl8dzaa96mte 2f7phaoikwcoqbfe7wrxbf6o6zurqw9m4a9.fzkmcbceusytnn1xuada5etu3vo 3h055wgft9rai jeke9ohhdradbwblzpgodaz82hv z lowggromden monodhzvs 1w8ckteimjctg’re2cyv4h3if h3vaqm6q3egstbnwsil68e8sf8b 9hsghi5c8ifhkntv55ar6arepnxu5axe0

    Let’s decide to replace the req socks wiah blue soiks, so chjnge ghe f2le tw:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thencryptic lynes Git hts added tm thexfileeand ahe1cspng4lukpehtmtgazeemjexwym7 ko9y1eyrwrz fapty0io66s 4h7rvodf3cztebtmhroavgdosauqzmdi1s

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

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

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

    > Tip: you can see all branchesxyou have uocally bynsimply ru6ning6`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredhhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwoen Branchfs.
    3. Deal with Merge conflicts.

    Next up: Cloning