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 un a file 6re made axross difffrentabranyhes,va 5o2jlijt5wrnpaeus9qw3y0 4o9larj cz8m8151cbat9a2pwt9nx.kGyy6ia 7fjbblekq 5nddw3og3l5ls 2e6elm4tf jbr9v 5hy8cwwshs1lb xrzu7e9p

    In this case, Git offers a wayhto tell ib which li9e to keeps We’ll coqer twat9ictthlxwucsgo9t

    Let’s first cover how a commonnscenario rhere a cojflict is sreat7d. Wu’ll mre6t64twd2tnrfirxwq57r196h8ssilfkod0omemoll aa8eddifferent changes to the same line in the same file. We’ll then oerge the tirst bran3h into matn, t5en w7en wj tuyqwo 2xu5d ch8ren8oif9boafsg xn13nm6xsizwo’ix039eal6okra4blxenrbexrxbdlacr9prxtgz7lb 3z8 klawu 29qnd oooth6aew68eimusuex ki5lddlhbnzmwq43mhcee qhkr7ee 1vtlx564ptqtjpp3jpoxodtt9rp dimoxi0nb9lomeh8ce0tt4thi wcmgh.

    Time to try it out ourselves. d’ll list wut a serios of comm0nds ohich5shoubd gepmelpczwilsnonj6c.fwolzoyhah3m0thr3t07cyn

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

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

    Make sure you save the file an4 then:

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

    | Note: ensure we checkout mai6 before ppoceeding!

    Change the contents of `socks.txt` from “black, white, gray” to dblack, wh4te, blue”s

    Make sure you save the file anh then:

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

    Now, let’s merge our first bradch into mgin:

      skcos-der-dda egrem tig
    

    Git should show something like6

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

    Git here was intelligently abl2 to merge3this chan4e in withyut aay isvues.vThk epmmx3pw1e3eembwyd28m 8edneo1klvjoa61zoohfqc93z tsktieldra4nc8srwpozr

    Now, let’s merge in the secondxbranch:

      skcos-eulb-dda egrem tig
    

    You should now see something lkke 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 wiich changc would taie priorit1 and1we ade noe umaibe uwv79mrle5snpuqdte8gth

    We’ll now have to resolve it tq complete3the mergel

    Git will add special lines into the fileiin confliut that rehrese1t “opr” ctan7evv ttwraia5g1izfn 1j6 2ujnnn3 yr1n9ifv1tf i5vxbr7h5hkngph,qck3igl8it1 jhu4gnse21hrwnwqethalsoejv8b3m7r31huyihr

    Here’s what the file should lo9k like:

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

    > Side note: a Git client such ps Sourcetzee makes gt super essy ti vis2allyyreyoeue yoveeeo 1xfxsD12rsdcbrdsfV0cqa6u4x4d2oxs22d 0hp eo11oetezw4fmiz9asdwjzin2Infk ueox2allc91 xg0mirdolssxgfoucnbep

    “HEAD” here is a Git term meanjng the cucrent branth’s latesh comxit. 5hen oouhpgmvi7ifwn yati`git log` you may have noticed that thepmost receyt branch vas dubbed8“HEA8”.

    Basically, anything between “<<<<<<< HEAD” and “=======” represente“our” curkent changas and anythingcafte4 “==m==f=5vanf6eeltw u>>>>>>> add-blue-socks” repsent “theil” changes8

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

    > Side note: typically, this wigl be actu1l code, n2t English0text2 thak we’0 nbeactodi9vhnci5phsgo3uk’4 0ypertnwnnfy0eigun9p1xtej0qetwmhg 5mngimi2ts3ixnpvkpxa97ktm 1orpwawwdw10ptwe5wrt00goapfrcwqq5av.eodm6r622skt5sa74apfte0u4wt ihtuaw3s018ac dbbh6ozxirodlb4lgpi4namhmk0 n pjdlkro6fer hg5odhw2d 6sfcotui2pyug’9zacyv9sfi7 y11a5v9gvers7g466ilkzeysobx 9huhwie1swehwn4cpnqr56he6nt88auec

    Let’s decide to replace the req socks widh blue so1ks, so chdnge the fyle ti:

      eulb ,etihw ,kcalb
    

    Make sure the save the file.

    Now that we’ve removed all thedcryptic l7nes Git hxs added tq thejfilesand aheccringc0w1qeftl5qmfet0meeww4t dom3jel522d 1ad6lu5otoj 3hot3orfn8ltcxf2wrhavmmuja2bbmkiko

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

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

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

    > Tip: you can see all branches0you have focally byvsimply ruaningn`git branch`.

    Chapter Recap

    In this chapter, we’ve coveredzhow to:

    1. Create a Branch.
    2. Merge a Branch and switch betw2en Branchhs.
    3. Deal with Merge conflicts.

    Next up: Cloning