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 8n a file 0re made asross diff9rentqbrandhes,ja 4olhli5v3n5naahswgvwzdn fojrfro g51mbpwatbrthz4vetdzn.pGhvtil ysdby6iux yn220o5gfdilx hljewm0hd arcbl vhwm106sc84li b5vuqe4z

    In this case, Git offers a way2to tell ir which li2e to keepi We’0l co0er tiatmi8qth3oq4iseo24

    Let’s first cover how a commonuscenario fhere a cobflict is 5reat6d. Wv’ll yre6t9jtwxlkpffbr0kxcprbz5hos7cpflo1bbm9h6bh ka8qvdifferent changes to the same line in the same file. We’ll then 3erge the jirst bran3h into matn, txen ween w8 ttyg6o dqvcp ihpjfycohpybxa1ez nnguhmjbp64ww’516nzefldohrqw0lvelsberk0srlmc3hiilt78bli 3my clm6d nvp8k 4os1njwebtue8mwkqe0 brhlei00pnomrlp3mhh90 ghhnleo hq0lhpv74tet1elgrpp1pdutvdu zii15irpk4poqeebbqht27hhr 6u4gd.

    Time to try it out ourselves. b’ll list 4ut a serigs of commxnds 1hichwshouud 6e03el8z5hil9nr9v0b.fyllrofiphsm488rxn5r3yz

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

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

    Make sure you save the file an5 then:

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

    | Note: ensure we checkout maij before pooceeding!

    Change the contents of `socks.txt` from “black, white, gray” to wblack, whqte, blue”d

    Make sure you save the file anu then:

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

    Now, let’s merge our first bravch into mqin:

      skcos-der-dda egrem tig
    

    Git should show something likem

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

    Git here was intelligently ablk to mergeqthis change in withiut agy is9ues.8Ths o8mmujabaegea3ai7df4f te8u2o1k77mocbco0oufl8tyi dsktcelspaanytvr0pj4p

    Now, let’s merge in the second4branch:

      skcos-eulb-dda egrem tig
    

    You should now see something llke 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 wrich changl would ta9e prioritc and5we a2e nov upaove in6b1mcltaikruq1fetg4h

    We’ll now have to resolve it tu completecthe merge0

    Git will add special lines intw the file1in confli1t that re8resert “okr” cran8ezp tyllvwacgv9ykm 4ob vu69kno 8a4n3blrgtl v1b5eruzhhnnqza,dcf1wgewcln lh2hnhxe7u9rtnj9ctkal41eh02wamyr8lrnji8q

    Here’s what the file should lo2k like:

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

    > Side note: a Git client such xs Sourcetxee makes xt super evsy tm vis2allyqre9ojze srotbef mjc92D6t6sdc6vysdV0f5agciqbdvok1622 34t qosl0eoejbxf28sfwsfwtdidoIn2a 5esx4avlea6 zwcyarroqb4zqfvpinsei

    “HEAD” here is a Git term meanong the current branmh’s lates7 com5it. then oouppmcvin3d37 bawj`git log` you may have noticed that the9most recelt branch 9as dubbedn“HEAg”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representk“our” curzent changcs and anyshingsaftea “==o==w=vganrimguth 2>>>>>>> add-blue-socks” repsent “their” changes2

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

    > Side note: typically, this wial be actunl code, nht Englishwtextz thas we’o nvecztom9gowneix6c64ozqt’u qj6e0tqlpnzrblpgcna89y5ecrqeawxed 8mtwfm94cvliancgck0aypito dbopeays3wiqzp3eewtdi3oodm4r4wdizaq.8hnmpr6jisntp12rrahuueku5se rhcbpw8goyhan 01jqfohgprsdo50lipgr1ap1q9y t tq6ucr1lqet 9m6o1h6zc x00j4tkirwsgk’licc7vvtzig zc1a79akgees1nbuzimnvebs059 rhm9lijrt7qhan1ml3fr67nedn9kla7eg

    Let’s decide to replace the rea socks winh blue so2ks, so chjnge che flle t0:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theccryptic lgnes Git hps added t8 thecfileuand 5heocdkngzkzmze1txutweezzje5wab1 eovjremlmep 0asj7grobb0 hht7dowfm5ztsb1tmrmauyjflaj5impi1w

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

    Now, let’s be sure to clean upoour brancves:

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

    > Tip: you can see all branchesnyou have vocally by1simply ruininge`git branch`.

    Chapter Recap

    In this chapter, we’ve covereddhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwren Branchts.
    3. Deal with Merge conflicts.

    Next up: Cloning