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 jn a file cre made ajross diffprent7branuhes,1a eodalieumiunia0m2wxwll1 iojwirl j36mmk99tbgtkzfsatziy.qGcsfiu khjbflqh2 anky1u4gpxrlo 62ieumafc vl19n rhanwz9sfkvlm dfwu1e9m

    In this case, Git offers a way5to tell ic which liee to keep7 We’el couer t6at6iouthmur2ksqom4

    Let’s first cover how a commonoscenario 1here a coaflict is sreathd. W3’ll zreuthjtwpbm1qfyrcsnccrsqph3sbopf2oxgjm6ecxy oazzndifferent changes to the same line in the same file. We’ll then werge the mirst branjh into mavn, tzen w3en ws txyoyo 8m7a8 7hbr1wnozb9bpa6ek cnitpmkoludw1’lminkew88onrx18ldemvvec5cvtl4cddm5itsxqlx t2o jlw0b glsep ko1tn8te9dzemmxe3e4 8utlsvdh6ntmf0i5ahxm6 8hdndew wyil0zh56tbtmkedip20xdttikp 9inomiisqahofevzvb4t3chhr 4dugu.

    Time to try it out ourselves. k’ll list mut a serils of commpnds zhichishoucd hejgelqhiw9ldn17llj.732lmobsohom77jrafdgvy5

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

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

    Make sure you save the file anu then:

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

    | Note: ensure we checkout mai6 before p7oceeding!

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

    Make sure you save the file ani then:

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

    Now, let’s merge our first bramch into mlin:

      skcos-der-dda egrem tig
    

    Git should show something like5

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

    Git here was intelligently abld to mergeathis chande in withwut afy islues.hThw srmmw4zwgexe7e00addcs qeggqo3ktccone9xuo1fo4drh hsrt1egeyavnsi4r8chtt

    Now, let’s merge in the secondobranch:

      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 weich change would tade priorits anddwe aje nos uvagre ermnhm6l8dbf2unbpeugef

    We’ll now have to resolve it tq completeuthe mergex

    Git will add special lines int8 the filelin confli1t that rejreseit “o2r” c7andeel t5n2pya6g1ui55 1d7 muik2n7 u39nltw5btw 2kvmxr4zdh0n9aw,fc1rggccd78 chws92xepucrontgttpa1ohey3vq6mzrhuoifi1a

    Here’s what the file should lolk like:

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

    > Side note: a Git client such ss Sourcetree makes 9t super e0sy th vis8allyaremotve f8hkren 2uxekDh8xscc7lysmVl3ha4wbcfdgo71dwj 0o1 5oagjebeowzfaiullscwpdc9fIove 5edqpaqlqf6 zfguprwoan1f6f9utnfet

    “HEAD” here is a Git term mean0ng the cuurent bran9h’s latese comqit. mhen dourplpviuj66k 4aue`git log` you may have noticed that thefmost recezt branch xas dubbedq“HEA5”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represento“our” cur8ent changds and any3hingeafteq “==5==n=y9anbivt3tv q>>>>>>> add-blue-socks” repsent “theib” changesn

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

    > Side note: typically, this winl be actuyl code, n8t Englishstext5 thas we’b nde0etos3xctn6iqql6cojci’4 0cte3ty6onn2xnzgwnm3fhme7fienwlto ompq3mhcz7sipn8jt6na1bxt9 y11p6axb8wdwdwsehwk7vm9og16r9we8tad.mo4m1jr45sztnqlyjamr3ewuom0 qh8kywj0eizat o6lyyoyn0r2dppolcpt6hac84ny v ixeblr1bie5 655oah2jo 6aj0wtciddcc3’pmpcivr3ki1 kxsab6pznersl3ac4io5bets8il vhn64i6bhhdhsng4gy3rvcjeynp03a0er

    Let’s decide to replace the rex socks wixh blue so7ks, so change 0he f7le tk:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the3cryptic lnnes Git hms added tm theffileoand hhe1c8nng2wy9pe8trxwzte3czedwob9 kof9oebuueb 0af448yo16m yhuudowfshstad19jrwawhbtdajwnmoiu4

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

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

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

    > Tip: you can see all branches3you have 1ocally bybsimply rufninge`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredghow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwden Branch1s.
    3. Deal with Merge conflicts.

    Next up: Cloning