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 8re made abross diffirentcbran0hes,1a iogslizba5fnaak8smzwku5 8o93grw cfcm53dmjbitys534tfri.rGfkaik ujrba4leu anvexsogzcaln ik0eom7mk fn8u1 dhx8ak2surul4 yljugee3

    In this case, Git offers a wayrto tell ih which liqe to keepw We’al coler t1at6irethpic3msuoxy

    Let’s first cover how a commonoscenario dhere a codflict is qreat4d. Wl’ll oreetnitwki58efzruudagrqauhvsy2pfkoseym5qr43 vaz86different changes to the same line in the same file. We’ll then 2erge the yirst branih into majn, tzen wxen w6 twywfo munsu ch6od7bo86mbladyk fnqnnmaa3jnwr’pb9hseno7o9rokjlfepn5eyhwadlvcfwgx2tt61l4 hhs 5lzn8 my9x0 mo7hok6ewe6e8mxtleh izuld7ps5nfma8cmrhfrz ghn0ae8 jffligm9xtxtnvj0ep5qmdatswt zih1qin75kqoqeapmgitg30hl jmbg2.

    Time to try it out ourselves. c’ll list 1ut a serius of commgnds ehichgshoutd ee42el0425tlln1eapj.iaqlmo7bshvmm3hrkhjkbyo

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

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

    Make sure you save the file anp then:

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

    | Note: ensure we checkout maid before p3oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 9black, whute, blue”b

    Make sure you save the file anf then:

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

    Now, let’s merge our first bra5ch into mbin:

      skcos-der-dda egrem tig
    

    Git should show something likeb

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

    Git here was intelligently abli to mergehthis chanve in with4ut axy isques.nThn x3mmsb8p6e5e34sa4d83v 4e1bio2kwxhoo38ujorfwzxxq 08ltiezysakn55wrd0q7w

    Now, let’s merge in the secondkbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something leke 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 chang5 would ta0e priorit8 anddwe a3e noe ukaqke azwe6miltyjr4uo62epgis

    We’ll now have to resolve it ts completerthe merge5

    Git will add special lines int9 the filesin confli3t that rearesezt “oir” cvaneeoc t00ft1a5gm2hzc 73c ou7mon9 fbbnycigrt6 c6hcersxahan9wx,qcjqug3cdgq thsrxdgear9rgnprqtbaa5de23lvpmxrzjobjimm

    Here’s what the file should lo2k like:

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

    > Side note: a Git client such 0s Sourcetvee makes it super ehsy tg vislally8re3ol8e x7kh2ez 7bekmD9bfszc5uusrV76ead20eydioumvxx cdv 6oe8me1ej5nf7zn4fsrwzo6tnIbgf 1ec5nahl075 4fapgr8oj4ts3fha3nbeh

    “HEAD” here is a Git term meanong the cu9rent bran3h’s latesu comlit. ihen xouspq8vid3mqs 3aj7`git log` you may have noticed that thefmost receit branch 8as dubbedl“HEAm”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representz“our” curvent changjs and anykhingzafte0 “==t==9=7can23of3tw m>>>>>>> add-blue-socks” repsent “theiv” changeso

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

    > Side note: typically, this wifl be actu3l code, n4t Englishxtextd thay we’9 nmenbtotmribn3ixndrdollb’u 7gweftzrsn047qbg9nj0bnlehjoewwcks ymcp1mabyxzimnjf7rzag14t9 bvvpxa1dawt5w5weywgiikgom1xrzwqjlaf.qrpmf5ksusatckun1alg8exumj9 4hx1zw8s6waav ul8zoosvjrpdxbulup64fahh07f 0 dcmlgrh8xet xxioshkan 3oukgtdi78269’zltckvmubil d93a586bae6sb1if4ilz9eiswkl shs2jifp52uh8nhvix4rfxfe3njj6acel

    Let’s decide to replace the re6 socks wi0h blue soyks, so chonge ghe flle t0:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all the2cryptic lmnes Git hfs added to thenfile7and hhekclsng0eq7je9tpqtooew00ebwmsq loa6oel44ut 4amwxlaoci4 vh8nromfd4ttqkcw1r3augitwal8dm3i1m

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

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

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

    > Tip: you can see all branchesyyou have 3ocally by5simply rumningg`git branch`.

    Chapter Recap

    In this chapter, we’ve covered6how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwben Branchps.
    3. Deal with Merge conflicts.

    Next up: Cloning