The critical figures here are what the relative speeds are, when the asteroid/comet is detected, what it is made of and how masssive it is.
After you've figured all those out the stage is set and you get a menu:
- party like it's 2012
- attempt to deflect it
- brace for impact and deal with the aftermath
Any attempt to deflect it has a large degree of uncertainty, including the trouble of getting humanity to pull in one direction for any length of time.
You'd have to develop the vehicle (and the fuel expenses to get the right velocity / direction are going to be terrible, they may be beyond current tech to make a manoeuvre like that, imagine meeting an oncoming bullet by matching speeds and direction where the bullet can come from any direction and you're sitting on a spinning ball), a plan to deflect the mass (by then you'll have burned up a lot of your time budget) and so on.
In context, if we look at the current state of humanity; sure some of our great minds have helped some (not all) of us to live pretty nice lives here on Earth. But on the whole, we're pretty good at screwing up basic things. Non-basic things, like for example having a Mars orbiter not crash into the planet, yeah, we screw those up too.
Anyway, I thought the OPs comment was likely more facetious than anything. Only in Hollywood can we expect a perfect ending.