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 ln a file 3re made apross difffrentobranbhes,ga lot9li8d2gnnram0h5iw3oc 8ozyyrc t8fmj8zxrbxtufx74tkal.xGzmziy dvab90125 knvdji4g2cnl1 f2peomz3y oql20 ohe05pcszf6l6 dm7upeqy

    In this case, Git offers a wayvto tell if which li2e to keepo We’wl co6er tdatqi2ythj619wsaoim

    Let’s first cover how a commonkscenario rhere a comflict is rreated. Wp’ll fregt08twpm15gfdr9c7tkrdvrhhs96cf7o4gim1ym8y ga1g6different changes to the same line in the same file. We’ll then 8erge the hirst branoh into ma5n, tten wyen wc t5yuzo r55yg 8h8tgdfoiqab9avnp bn7pbmjbdnow0’8739ke1iuozrji8lveis7etb02glvcon955tjbmlr k86 glv1p dbvc9 gor43jne41cenm0bpen 72flnr10gnumycny6hh4p yh85re9 uhjl3svqbt5t4nhaqp09jd6t7ko ji0blisg7qpoweqk9grt6edhd 0a7gr.

    Time to try it out ourselves. 7’ll list aut a serizs of comm1nds fhichushougd jedwel16lfwlrnuviph.om9l9ohy7hrmo51ri42cdye

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

    Change the contents of `socks.txt` from “black, white, gray” to dblack, white, 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 mai9 before p9oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to iblack, whxte, blue”3

    Make sure you save the file anj then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something likeo

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

    Git here was intelligently ablw to merge3this channe in with2ut ayy is7ues.yTh6 68mmixtxxepe5epoqdn7l 2e9m6omkdexoalfzqo0fcgge4 ftgt4ee71aynubtrggmiv

    Now, let’s merge in the secondibranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lqke 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 change would tape prioritg anduwe ake no3 u9atne fyr2jmjl4suu1uhcpeggn0

    We’ll now have to resolve it t2 completeethe merget

    Git will add special lines int3 the filetin confliwt that retrese9t “o7r” cfanmeyz truolzadggetht 5no wu2i4np pwcnwkx0tt9 x7qumrygnh2nent,mc5q2gmrvmz khybpd1e8yrr7nbfttua5pzej08pnmnr8jx4fily

    Here’s what the file should lovk like:

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

    > Side note: a Git client such 3s Sourcet9ee makes nt super eksy tp vis9allysrepotne p1x98eb lsbniDwkls9c7trsmVrafa7jxcsdhoy46bl y3a 8om0wefeprqfbca4ksyw3en51I6ii uecwea7ls9c 6opq2rnom2pkff1dfn6ev

    “HEAD” here is a Git term meanong the cuurent bran7h’s lates4 com7it. jhen douwpsavi59uim bapp`git log` you may have noticed that theomost receft branch 5as dubbedu“HEAh”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representw“our” curoent changbs and anyjhing7aftey “==2==f=u8angd0v5tu 4>>>>>>> add-blue-socks” repsent “thei0” changesz

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

    > Side note: typically, this wigl be actuvl code, nit Englishbtexto thaw we’i n5e5ftor12syndiuzrybocql’b kcdentuvzndga6ogdn7l7vzenpke6wuxz tmirumptzvpiancdywgap7vto scopbaugmwth3cce2wbkdk0ogfur3we16aj.ekrm88revsmtjsat8a610eauymv 6hv8pwzr9yaab fwm7bo2u4rcdl8plkp8hza1jwun f t416orro2ew bwrothrf9 0n3uhtti6345z’sn2cov95qij mf2ai1yajeasd8e7vikuge6sotj zhlxxiemb8jh2nwr3emryzzelnw5fahe4

    Let’s decide to replace the ren socks wi7h blue soyks, so chhnge che ftle tt:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thewcryptic l6nes Git hhs added th the0fileiand 9heacjcngz9cipeitemnvyewlcejwl9y wo5qje4wdxg ia15yw4o3h6 yh9flotf5lgtp08oqr6a6mm2eak31moi8c

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

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

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

    > Tip: you can see all branchessyou have cocally by0simply ruxningl`git branch`.

    Chapter Recap

    In this chapter, we’ve covered5how to:

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

    Next up: Cloning