How does the Earth's magnetic field protect us from Gamma rays

…since as far as I remember Gamma rays being neutrally charged are unaffected by magnetic fields.

Are you sure you don’t mean Cosmic rays?
Because, those are high-velocity nuclei, and carry a strong positive charge.

Agreed beowulff. If we every got hit by a gamma ray burst we are toast.

Maybe, maybe not:

On the other hand: When a charged particle (such as a high-energy proton) hits the upper atmosphere, it produces a shower of all sorts of other particles, including gamma-energy photons. I wouldn’t be surprised if the majority of “gamma rays from space” are the result of this, and you can prevent those if you deflect the original charged particle.