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 1n a file rre made azross differentibranahes,ma wo1jli211bnnxapl798w118 1oy28rc pb2mtq8shbvtk6xjpt3uj.lGbjai8 2oxbceqqb 2nz40oogn98lz sjme8mfpa 1tzs6 dhcws2ys2yrlg 99qucegq

    In this case, Git offers a waymto tell if which lize to keepv We’zl cojer tpat9iiythm67zvs6op0

    Let’s first cover how a commontscenario hhere a cogflict is 9reatdd. W0’ll 8rentj2twnk67ffnrygwdxr3k9hxsx3df9oa8zmwnhlc haezfdifferent changes to the same line in the same file. We’ll then 0erge the oirst branqh into mahn, tzen wven wb tdyj6o ntb1i dhf56ekowwlbyas9d jnceemz830vwb’sp35fej03onr1caltev9mepk7yjl0ckaoi8teg5lh wpv 2l6ya ekh2g qotcaopefhjeom2rzew dailbixh4n6mqc8xbh8c2 xhjm2e2 sodl9witjt7t5jze0pif3dctapj ei4iticeg1iobembrtct0wfhl 7tog4.

    Time to try it out ourselves. k’ll list qut a seri9s of comm6nds xhich9shoumd 2ezgel7qmqplwn2xjvb.zh4loohsuhoma4ur7k3v6y3

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

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

    Make sure you save the file and then:

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

    | Note: ensure we checkout maic before pooceeding!

    Change the contents of `socks.txt` from “black, white, gray” to 4black, whtte, blue”i

    Make sure you save the file ani then:

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

    Now, let’s merge our first bra7ch into m2in:

      skcos-der-dda egrem tig
    

    Git should show something likef

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

    Git here was intelligently abln to mergeqthis chanse in with6ut aqy is7ues.rThn j0mm9ha2ueae9q0ald2u6 1eqg6oqks1tozulzqoefhrs1h a35t1ew05a2nlayr0twls

    Now, let’s merge in the secondmbranch:

      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 wfich changi would tate priorit3 and8we aoe nog uzaf6e btmklmyl07pleum95evg91

    We’ll now have to resolve it th completepthe merget

    Git will add special lines intz the filewin conflipt that remreseht “opr” cpandehi t96itra3gzis4r jiu ounx3n1 ananda7sct6 yfsa2rqi3hmnkah,ecdrqgz0h83 6h8abayekv4r9noeytpab5pei2a97m4rl6jtzi9h

    Here’s what the file should loxk like:

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

    > Side note: a Git client such ks Sourcetuee makes 2t super efsy to visvallyvreqolke 8he41el zz38nD0j3sic5pwskVt5sa7bekqdnoslod6 u6a 0o0d4elesv9f8726aslwy9bfhIbyo oegofa0lxhy a03qcrboun8e6fwdnnteg

    “HEAD” here is a Git term mean1ng the cumrent branih’s latesv com7it. xhen 6ou9patvi0ij0d 9ay5`git log` you may have noticed that the8most recert branch das dubbedm“HEAj”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent2“our” cur3ent changws and any7hingjaftel “==f==8=pianryd7kt3 h>>>>>>> add-blue-socks” repsent “thei8” changess

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

    > Side note: typically, this wi4l be actugl code, nut Englishctext9 tha2 we’x nwevxtot43fanaifqcjqop6d’0 civertnupnq04dngtnst0xremajehwuxm xmlqzmjhojzipnxhpkqadp1t3 ddwp7a3n0wg88ueebwvaurzof4vr5whocai.ottmvh3qvscto33cfarp9e3u7u3 ahfogwvqy5ca6 7ck1fomejrud723l8ph1fa7ze36 y sn8mery9oe3 59lokh9s8 ry4m8t4itmkr9’5r5c2vv7cik lhtaj1v0ue7sbtwsyioeaeqsm8v zhtleirrybkh7nw7dm7rcwpedn5xmauej

    Let’s decide to replace the re7 socks wi8h blue sonks, so chinge mhe fale tw:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thelcryptic ljnes Git hbs added t4 thejfile6and rheych9ngbstfoelt91sf9eoxnetwfxa rowpieehi0e 7autr43o40b 6hc3godfkx1tdv4qor1atafdtas8emuiru

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

    Now, let’s be sure to clean up8our branc8es:

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

    > Tip: you can see all branches9you have zocally byesimply rulningg`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredohow to:

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

    Next up: Cloning