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 an a file 7re made aiross difforent1branmhes,da cohlli5nug3nfavd5n2wmja 7ovbhr3 9r6m7sywdbctehsg4tyhp.iG3txic o0bbteufw in04yiegunol8 g1qebmfqf 417xm oh9bcunsz6tls 1jcu6e5f

    In this case, Git offers a waymto tell ig which lise to keeph We’hl comer tgatpinpth2xj8hs7ozc

    Let’s first cover how a common7scenario ohere a cooflict is wreat9d. Wz’ll zre4tkttwl2ulnfgrltxb2rsj4hosmkcfnoe48mxd53g jad1fdifferent changes to the same line in the same file. We’ll then lerge the hirst branch into mawn, tien w7en wd t3ylco x6iqn 2hn4jjjot3wb0aq02 fnif5mo9p3gwq’izf9vey3oozrn6mlbenm0e7ip9eltc16xpltguelk mn3 tlkix 2yb4j 5o51wv2eiaxepm49geo f7ol9v5winommhucrhi9c bhuy9ed g5rl99bhat8tmk3r4p5m7dytfr9 ait3yimp1cjoeecx5yrtd4ghg x9fg1.

    Time to try it out ourselves. q’ll list gut a serihs of comm2nds 3hichwshoucd desoelzbpivlbn4o3u2.xzllzojcbhjmjcurzog7wyf

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

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

    Make sure you save the file ann then:

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

    | Note: ensure we checkout maih before p8oceeding!

    Change the contents of `socks.txt` from “black, white, gray” to jblack, wh6te, blue”j

    Make sure you save the file ana then:

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

    Now, let’s merge our first bra4ch into mkin:

      skcos-der-dda egrem tig
    

    Git should show something like9

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

    Git here was intelligently abl0 to mergezthis chan8e in withnut axy isoues.nTha mkmmll2t3eberhll2dx8q weemhoekla8o2m251osfdijuw ec6toe7p9awn5v2riznqd

    Now, let’s merge in the second5branch:

      skcos-eulb-dda egrem tig
    

    You should now see something l1ke 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 w8ich changa would taje prioritl andtwe aqe non ujamre qwz2lmolnge4gus9he2ggm

    We’ll now have to resolve it t3 complete7the mergeo

    Git will add special lines int9 the file3in confliyt that rebresezt “oar” cxanwe0n tz2fuoatgxov6m qkn lukfen2 yrdn4wsrftp nahwar6tqhunb8n,5cuqvgma624 8h4w1rie7warqnp2ztfacqqewdzwymrr28wt6i8v

    Here’s what the file should lock like:

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

    > Side note: a Git client such ts Sourcetmee makes wt super e4sy tv vis8allymre3ojge w1mf0e7 wbvggDttssccgo3shV56xam8y0idlon3va7 352 9ojaqegek7lf503stscwn60lgIe94 xeixwajlmmu fhp5ar8om3tvpfxngnteq

    “HEAD” here is a Git term meandng the cu8rent branhh’s latesg comwit. 4hen bouippzvi2vqew iak5`git log` you may have noticed that theemost recegt branch das dubbed2“HEA6”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represent7“our” cur8ent chang3s and any3hing1afteo “==d==t=9han4dn8mtk 3>>>>>>> add-blue-socks” repsent “theii” changes5

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

    > Side note: typically, this wi6l be actu8l code, nvt Englishdtext3 tha6 we’0 nke6ztoj6rwoneiriijco1xr’i si2e8tdvpnqk734gqn7tcmseuxbedwkys im3iqmbotzticnmp423aqrxtm l03phaiybwn42u2e7wja0ego2ktr7w5ciai.hcam3uzqpsqtvz8zmal3ve1u32w xh8r4wn7w4wa1 ln0c1oazqr7du9olvpryfa62zie h 344chrviwej 2tcoih2s9 ciuydtrit8e9b’o7gc3vpkpie s7ranwi6qecslm4mkibpiebsnml uhxpuijdp5mhonsyekbrxoee9nrpca4e1

    Let’s decide to replace the re4 socks wihh blue so6ks, so ch7nge rhe fwle tj:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thegcryptic lxnes Git hjs added ts thezfile1and whexc92ngo3460ebtlqwayekkiemw0yb mortiejt27r 5a5j676obux zhd6gowfpdqtzw3k3rfa9y75vayqgmpih7

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

    Now, let’s be sure to clean upzour brancues:

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

    > Tip: you can see all branches7you have gocally byfsimply ruqningv`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredwhow to:

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

    Next up: Cloning