What would happen if a gamma ray burst hit the Earth?
We will be toast! In simple terms, we will die due to immense energy.
Gamma rays are the most energy intensive waves known. A direct hit would likely eliminate all life on earth. Gamma rays have very small wavelength. As the energy is inversely proportional to the wavelength, it has very high energy.
If a gamma ray burst hits Earth the effects will depend on how far away the source is.
For a gamma ray burst (GMB) to have impact on life on Earth it needs to be relatively close by and aimed directly at the Earth.
The Earth's atmosphere is very good at shielding us from high energy photons such as X-rays and gamma rays. Very few reach the Earth's surface.
For a GMB to cause problems it would need to be within a few parsecs of Earth. This would increase the levels of ultra-violet radiation reaching the surface and would increase levels of Nitrogen Oxides and other harmful chemicals. The effects would only last a few years. The closer the event is the bigger the damage would be much worse.
No GRBs have been detected in our galaxy. No stars are likely to cause an event close enough to be harmful. It is very unlikely that one will occur close enough and be directed at Earth for the foreseeable future.