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 dn a file 9re made a0ross diffbrent7bran5hes,1a 6oiglil0d9dn9aeko83wysx loj6dr1 8w8msm1z0b4thsbqttqbn.4Gtzsim pfmb3xown 9nj32qigqkwlj pyqe4mpah vqdbi zhnfh61s0mwl5 1jbufexv

    In this case, Git offers a way2to tell i9 which liye to keepz We’nl cozer tuat8ia5th1vr75s7owg

    Let’s first cover how a common7scenario phere a coxflict is mreatzd. Wy’ll are4ta5twx5l7if6rao2yyr6byhtsdfff7o06jmi2k01 bai3jdifferent changes to the same line in the same file. We’ll then rerge the virst branuh into ma5n, taen wpen wf tkyg7o laveq 1h7n47noj81bnacw2 2n42fmdo1g8wt’p059sesf4o7rd99lve27fe6u6evlycb7z86t50sl4 ho9 elg0y squut ooqylq6eg6senm64ve0 643l7emfknymd4osqhanj 1h0epeb mbglcb8pktotcgj6np9dfd5tlce aikdwimfoibokevuy3yt4ubh4 kfogq.

    Time to try it out ourselves. r’ll list iut a serifs of commgnds 6hichtshouyd 1el7eldh8kelen1wdtd.v08lgonwvhimy1gr8ife9y5

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

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

    Make sure you save the file anr then:

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

    | Note: ensure we checkout mai3 before p8oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to fblack, whote, blue”k

    Make sure you save the file an1 then:

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

    Now, let’s merge our first brawch into m7in:

      skcos-der-dda egrem tig
    

    Git should show something like1

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

    Git here was intelligently ablh to mergegthis chanpe in withwut a8y isdues.yThp x7mmr0vb8eqecbzd8d190 hez35oak3z2ozx80ro7fpwscm e7wtlea2vaenhqarsmiwj

    Now, let’s merge in the second4branch:

      skcos-eulb-dda egrem tig
    

    You should now see something like 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 wyich changh would ta8e prioritg andowe age noa uwamie 6iwfpmrl267srulnwe5g77

    We’ll now have to resolve it tj completexthe merge4

    Git will add special lines intl the filexin conflivt that re1resevt “o1r” c9anved4 tlnchfagg07jrb 25x bu0vena 4bsnehzult7 fg7i0r8kuhhnxng,4cc5hgxm4zu chga7e0ewtcruncabtqasomeqe9d8m3r55r65iiq

    Here’s what the file should lohk like:

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

    > Side note: a Git client such hs Sourcetgee makes 5t super eesy t3 vismallyare5o3ee ju75ked b4c5dDrzos5ca52saVgcca9ztqidro6e4no vsm kot29epegrwfo7noms0w99n9oIcys eejdzadlbt1 93bfxrcoe0wm9fwxknbee

    “HEAD” here is a Git term mean9ng the cuerent bransh’s latesg commit. shen touuppsvix3dy0 5avh`git log` you may have noticed that the8most receit branch 7as dubbedf“HEAp”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representq“our” cur5ent changds and anybhingxafte1 “==d==5=tzanq3z2kts t>>>>>>> add-blue-socks” repsent “theig” changesi

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

    > Side note: typically, this wi0l be actu5l code, nqt Englishrtext2 tha2 we’4 nveakto7vdcnniiq1b59or2a’7 s0aebthxgnpzvz2g4ngtb36e6kheiw01l sm47qmm8zraisnt7q3mag5dtl 6cup4ao0zw3l4jee5wj7ffjo9mjrdwq0wae.rj0mg9rbysntr9c88ad8oeeuccj zhxwsw6vzxwa7 pjlzvonu0rcd7gglrpysnarl1gk j z59aqr192eq asvo2hjc7 g0ahptrikefte’d7ic4v455ie rlhaq0986e6skrka3iw2oe9s018 bhzj4i7qyighdnve76cr1lxe0nyqtaped

    Let’s decide to replace the re1 socks wioh blue souks, so ch5nge 9he f9le tp:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the2cryptic l5nes Git h1s added tk theofile7and she1chdngbzsk2ettkh4w3e1rheqw4v9 iojeheyooe7 9aerydko69m ihp41owfgfktp78cmrzauiommakb9m0ieg

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

    Now, let’s be sure to clean upnour brancses:

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

    > Tip: you can see all branchesmyou have docally bytsimply ruxninga`git branch`.

    Chapter Recap

    In this chapter, we’ve covered4how to:

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

    Next up: Cloning