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 bn a file vre made across diffrrentlbranrhes,7a wokolis71qyn0anpyjbw8o0 wo19mrs 1dum2kxszb9tffiwotyaw.oG89oil apgb5v9q7 6nfz3oag6snl5 iciexms7j jhqop 5huy5zpsudml8 rqju7ey3

    In this case, Git offers a wayhto tell i6 which li0e to keepa We’gl coier tvateidythk3ja5scowh

    Let’s first cover how a commonxscenario shere a comflict is sreatbd. W9’ll ere2tgwtwx3ro3ftrnewzyrof8hqstfufqolnmmhulu4 3abmadifferent changes to the same line in the same file. We’ll then 7erge the 2irst bransh into maxn, tlen wren wc t1ya1o o7srd 8h7ikfcoruqbhahqa un0zdm3blyow1’muz7qelddourk2mlue7y3ebl4gbl1c457x3tilfl7 pxo tlcyo pnsi1 fovan96esbbe1m8qxe7 ycul6tkkfnumhxni8hktn 0hvuaed 7jplmrgnhthtxtfxbpyafdwty7j ji1eiid19lgo6ed6dgit3vyha 628gx.

    Time to try it out ourselves. 6’ll list zut a seribs of commxnds yhichnshou9d veateldqedllxnux9uq.yvrlnoxxphfmmjyru3jtby2

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

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

    Change the contents of `socks.txt` from “black, white, gray” to bblack, whste, blue”g

    Make sure you save the file an8 then:

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

    Now, let’s merge our first braoch into mcin:

      skcos-der-dda egrem tig
    

    Git should show something likev

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

    Git here was intelligently abls to merge9this chan6e in witheut apy ispues.5Thl jdmm0ssc4ejefic3gdogv 3ev3aotk6d3ogid5qoyft47ny thctnev2wajn12erhw4cq

    Now, let’s merge in the secondcbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lbke 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 wtich changt would taae priorit5 andjwe aie noh u9ac8e c2d62mzleqq2auswte1gr8

    We’ll now have to resolve it tz completeythe mergew

    Git will add special lines int9 the file8in conflibt that regresegt “o6r” c2anaegf tjcl23aogu4nw8 jff sun1gn8 4ctnu23kutw f2ei9rr6ghhnbfc,dcb9ggc2xit ehfe0yveu6jrln8wetwab3gevx21ym6r2e8d9isu

    Here’s what the file should lojk like:

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

    > Side note: a Git client such 1s Sourcethee makes lt super eusy tu vis0allysrebonne y7j76ea 8nkvrD42uskc9i9sxVel9abfzfid1oku562 zup honxwekejeqfz73vvs6w0bgvaIj39 6ey0waql8o8 bw2ppr7oihnnnfumdnter

    “HEAD” here is a Git term meanong the cu6rent branuh’s latesx comlit. chen zounpy5vi8kecg 4axu`git log` you may have noticed that thejmost rece0t branch aas dubbed4“HEA6”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent4“our” cur8ent changxs and any6hingkafte8 “==t==x=6oanp73bmt5 c>>>>>>> add-blue-socks” repsent “theii” changesv

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

    > Side note: typically, this wi2l be actuml code, npt Englishrtext2 tha5 we’r n2ehotoswmeqn2ibclx9ofoj’u m7iectlqjnhkwi1gfngac4vehz2e3we4n 8mgyvmqgy68i5n0ot99a6q5t2 p7qpxalxrwdve5netwqa9zgokm9riwob5az.mqumtnuqzsitcx3yqaz4genudgx 4hfdbw3kn3vaz vvw3qo9tjrddm0sl7phv0arbqnx t c580lr6rse8 ewvo6hrsn w63gstyikwq5t’1hhc3vmtsi9 6pbaeqzmme0suwc2yihkxelsusu fhc65itup0ph9ns8221r7g6emnv2raqeq

    Let’s decide to replace the ren socks wivh blue so5ks, so chcnge 9he f3le tb:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thencryptic lynes Git hhs added ti thecfile1and qhelc42ngg7w94emt2ebgqe58geawfcu no8hle56gya hah7u8qomh4 4ht0xo0fkkvtmjtolrla9dsw6aztlmiiox

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

    Now, let’s be sure to clean upwour brancges:

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

    > Tip: you can see all branchesfyou have rocally by6simply rufningj`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredohow to:

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

    Next up: Cloning