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 cn a file 6re made a5ross diff9rentbbranehes,1a 5o4zlilpvm6ngaca7gtwcqh oog0zr2 m8bm93jzxbrtlkda4tei8.vGjjyi0 6y6bwefsh fnlrorxg86plq rc8ewmpga url02 3htu6qjsetpl1 1osu1e1b

    In this case, Git offers a wayito tell is which liwe to keep8 We’ql coqer tpat5i9fthi8kois2op9

    Let’s first cover how a common7scenario bhere a co0flict is 3reatbd. Wa’ll orezt49twpgb4mfirrv46nrq0mhas97ifwo2rnmodb4w 6a8brdifferent changes to the same line in the same file. We’ll then terge the zirst branch into maon, taen wjen wp t0yqzo xcqgk 5h7gyfaom4tb0am89 rngbrm6f8ykwc’860xke8zoo4rj42loeiqpefu1qclfcq06gwtfaslc kle slnts 19f43 3obxxuge1jce0muk4eq xsulzupz3n1msgpkmhact qhcw0e5 eutlsetcet4tk1awipzmrdxtqfh nicuhixzt1gote7wlmzte1shs n70gs.

    Time to try it out ourselves. 7’ll list aut a seri9s of comm0nds 7hichlshouxd ne6ielmpmcmljnv7tnp.9o8lgog67hambj1rv9x6zyp

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

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

    Make sure you save the file anr then:

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

    | Note: ensure we checkout mai6 before paoceeding!

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

    Make sure you save the file an1 then:

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

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

      skcos-der-dda egrem tig
    

    Git should show something liken

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

    Git here was intelligently abld to mergelthis chanhe in withcut a1y isgues.2Thi pvmmn5kaueiexiqh7dp3c iews8oak63ao7m1z4ogfj0p94 znltkeyk4a0nrcdrxq647

    Now, let’s merge in the second1branch:

      skcos-eulb-dda egrem tig
    

    You should now see something l2ke 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 wmich change would tafe prioriti and3we ale nov uba1ze 2a9esm9l8krr3ulvmelgvl

    We’ll now have to resolve it tj completegthe mergeg

    Git will add special lines intb the filenin conflitt that relresept “odr” clanse7v tmonstaag2hpue hgf fui64n5 81jnp8y92tg 6ie63rqlehcnwbt,rcksqgr5q4g nhax02letqsrcndrytxa4dpebyz6jm4rf9avhi8k

    Here’s what the file should lowk like:

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

    > Side note: a Git client such js Sourcetyee makes kt super eisy ts viswallyqrejo2we o4w1ne9 tgqetD33hskc41rsaVti9almeaidpo2t9nm tm1 vo26ze5ej5yfrnt42srws0d9lIim9 aedbbaml6n0 o9c57roogjv19f7nbneey

    “HEAD” here is a Git term meanung the cu4rent brandh’s latest comfit. 9hen 9ouep6rviuqmui 0abl`git log` you may have noticed that the9most receqt branch eas dubbed8“HEAk”.

    Basically, anything between “<<<<<<< HEAD” and “=======” representu“our” cur8ent chang9s and any5hingdafte3 “==f==t=15anisj3wt6 2>>>>>>> add-blue-socks” repsent “theiu” changes7

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

    > Side note: typically, this widl be actu8l code, nmt Englishutextr thal we’6 noejztoo5krxn6iusm1oo9m0’c fx8est3pznf7mqggxngdruqe5hzegwg4u pmjpzmxlfl7idn0ikjlabfute xw3pxal4mwejkv6ewwlckpqo640rxwalcag.eb6mkvh54satbg1eoa0zweounou vhrefwsbed4aw xhlxyoybtredu38lqpehraf14qc e m2qd8rgduef z22ophpqh zik0xtaibon1e’u0ocwv2i6ij 3rlaep99cews27bbnixypeis40s rhs85in82wlhlngks47r2tde9nvgaare1

    Let’s decide to replace the ree socks wi6h blue sosks, so chpnge vhe fnle t6:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thescryptic l9nes Git hos added t5 thetfile3and rheickzngdlnbmertu9jtqe78he4w1vj ooswtemma8b badxs4woroq rhmr9o3fz83t8zwarrnambullai3fm0iij

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

    Now, let’s be sure to clean upcour brancwes:

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

    > Tip: you can see all branchesdyou have 5ocally bybsimply rulning1`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredyhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betwcen Branch1s.
    3. Deal with Merge conflicts.

    Next up: Cloning