While it's really easy to just look at a giant space rock and say "let's just blow it up", there are far more interesting and complex options, including just hitting it with something
People smarter than me call it kinetic-impact, and it could be a fairly effective way of knocking an asteroid off its course without the use of nuclear explosives. The idea is that we would ram something into the asteroid as hard as we could to push it into a different orbit or off its course, thus missing Earth. This basically becomes a huge example of a collision problem. Which means, of course, that NASA would need to know the mass and velocity of the asteroid so they could send something big enough and with enough force that it would actually work. Plus, they would need to know years, maybe decades, in advanced to actually pull this off. However, even if they gathered all of the relevant information, there could still be one issue. It would probably be safer to lodge our projectile into the asteroid (what if our projectile were to come back towards us?), so the surface of the asteroid would alter the outcome immensely. If it were too hard, our projectile might not be able to lodge into it. If it were too fragile, the asteroid might shatter, and then we have a whole other problem on our hands.
While no research seemed to show that this has been properly tested before, it seems we got fairly close with the Deep Impact mission of 2005. They launched a probe straight into a comet to see what it was made of, as stated by aeronautical engineer Rusty Schweickart “In a way, the kinetic impact was demonstrated by the Deep Impact mission back in 2005, but that was a very big target and a small impactor that had relatively no effect on the comet. So, we haven’t really demonstrated the capability to have the guidance necessary to deflect a moderately sized asteroid.”
Essentially, the main idea behind this plan is that we could knock it away without the risks that come with blowing it up. It certainly is not as effective as the use nuclear explosives (which, honestly, we would probably use if the time comes), but it is a different take on the idea.
I don't have a witty tagline to write at the end like I usually do. ¯\_(ツ)_/¯