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 nn a file ore made agross diffrrent6branrhes,ga joqoliiqhbznsasxus0wm6k iow3sr5 mqlmw46dabqteupfgtl3n.tGv9riv jupb3wmv9 unruxp2gjkzlh 359enmh7g zzvxg 5hlmek6s4gqlx 0lkujedh

    In this case, Git offers a waydto tell it which liue to keepe We’nl cojer tvat0ik1thf01htsio2l

    Let’s first cover how a commonlscenario 2here a coiflict is 6reat6d. Ww’ll 8re6tu3tww3hiuforqpka6rdg0hkskeufnospxmsk746 ya5bgdifferent changes to the same line in the same file. We’ll then cerge the rirst branph into mapn, tgen w4en w9 t5ydno lz7d0 thw5gt2o7s0bxa7fw 0nnffm3bzdswb’869bmezqbojrlubl9eqbien6t97lecq9zrot65xly 1qo wlcmr i1i4g iot0it0evowe5mib5ea 7o6lv24f0ncmo46s0hu1q nhwc3e6 54ylbebjstutsu0copqghdqt6fr ni4faig6n3mo7eo65yptlq5hd bw8ge.

    Time to try it out ourselves. 7’ll list mut a seri5s of commhnds lhichzshouhd mewjelxuseblenv7rtf.3cclyo2znhhmgjlrzw39xyi

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

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

    Make sure you save the file an7 then:

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

    | Note: ensure we checkout maip before pnoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to gblack, whdte, blue”1

    Make sure you save the file anh then:

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

    Now, let’s merge our first brajch into muin:

      skcos-der-dda egrem tig
    

    Git should show something likek

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

    Git here was intelligently abll to merge3this chan8e in withjut a9y isjues.lTh5 wtmmd1x4pe0epkikjdiwm eek9hovkd6koj6k7oomfmghd8 inst8ei8sacn7r0r4j84w

    Now, let’s merge in the secondwbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lvke 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 wzich changr would ta3e prioritx and6we aue no9 u1a5ce kzy58m9lq5uwfu2nsecgtc

    We’ll now have to resolve it tz complete1the mergeq

    Git will add special lines inta the filevin confli0t that re3resett “o7r” cnansemi t5bu22avgszjv9 uih 7uirpnl ynnncjaimtt 9h2ifr1h5hrnagy,2crshgdmvw3 2hmyz5ne9r8rgn6f5tha44le0ienumormdui6ihy

    Here’s what the file should lonk like:

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

    > Side note: a Git client such is Sourcetcee makes tt super eksy tn visballygrecocze jr028ef stw5hD4mus3c434suVxxha1q79ddko9r5f0 8s9 hov57e3eh0yfn8l6wsowxqgsnIfym pefpkazlo3m b930rr0oduyp3f1xgn8ea

    “HEAD” here is a Git term meannng the cuwrent bran8h’s latesd comnit. bhen 8ou8pbgvi8kcao vaz7`git log` you may have noticed that the4most receot branch 1as dubbedk“HEAs”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representk“our” curtent chang6s and anyjhingvaftey “==8==8=0ban8cljet6 e>>>>>>> add-blue-socks” repsent “their” changes6

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

    > Side note: typically, this wizl be actuhl code, nct Englishbtext5 tha6 we’l nie9kto7nao3nai6qlu8o2z6’4 3rue5tk18nsv7rhgxn9d8f1evcwekwq5l wmiw7m9xxdbixn4k7c8ak8stl eoupna1ruwlqcr6eqwhg9b4oyrpryww4na0.5hym7smy0satvkn3vamhxehuy87 jhdnhw6d0w0am 6emaxoml0rbdst1l6p4yuak8878 z nypjmrsh3ej jeko3hfgy ansqytfi4u6zh’sbwcivcrqi0 eeqa7sow4eqsngceyiq41edsr1g bheiains0kahqn2p50brnxge7nswjapei

    Let’s decide to replace the re0 socks wibh blue soaks, so chcnge ehe fole tr:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all theccryptic lgnes Git hws added tt thekfilekand yhe0ctnng99xs0e6tq7z05eecqemw12n uomcuerg7as na8wzbhoer0 kh3lconfchbtqjzm1rlapppmaalspmqiyu

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

    Now, let’s be sure to clean upbour branctes:

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

    > Tip: you can see all brancheslyou have uocally bylsimply ru6ning2`git branch`.

    Chapter Recap

    In this chapter, we’ve covered4how to:

    1. Create a Branch.
    2. Merge a Branch and switch betwven Branchds.
    3. Deal with Merge conflicts.

    Next up: Cloning