First thing to say - the movies tend to focus on big civilization threatening impacts. But they only come every few tens of millions of years on average. That's a long time. And they would not wipe out humanity - in this the movies just get it wrong, they are nowhere near big enough for this.
There were big asteroids big enough to wipe out humanity in the early solar system, and we see their scars on the Moon as the largest craters and the lunar seas. But though there are plenty of objects that big in the solar system they are in more or less stable orbits now or so far from the sun that there is almost zero chance of anything like that now, as you can see from the absence of any really large craters in the geological record of Earth, the Moon, Mars or Mercury in the near past. The larger craters are all overlaid by numerous smaller craters and so are obviously ancient.
You'd expect something civilization threatening (not extinction causing) only every few hundreds of thousands of generations of humans.
As for extinction causing impacts, it's not even on our list of possibilities.
And - it's a probability thing of course - but you'd expect many far smaller impacts, large enough to cause huge tsunamis and destroy cities - but not civilization threatening - first. And they are small enough to divert given enough warning. That's mainly what the SpaceGuard programs are looking for - or at least - most expect to find.
So for instance, a 1 km size asteroid - a major disaster of course - worse than any disaster in the last century - but still - too small to really be civilization threatening and far too small to be extinction causing, would hit us every 44,000 years or so, roughly every 100,000 human generations.
The Space Guard program is of course looking for those also, on the remote chance that one of them is headed our way in the near future, but they are mainly concerned about smaller impactors than that, of the tens or hundreds of meters scale. The larger 1 km sized or larger objects could also be diverted given enough time with a steady push over a long period of time, with various ways to do it.
Impact event - frequency and risk
WHO WOULD SPOT THEM
It simply couldn't be concealed if they tried. Small even km scale objects yes, our map is pretty good but not complete yet.
But you are talking about hundreds or thousands of kilometer scale objects, similar to a medium to large sized asteroid. Those couldn't be missed.
Amateur astronomers - some with very large telescopes - could spot an incoming asteroid or comet as large as that easily. .
Wouldn't need government programs. Indeed amateurs might be first to spot it, not impossible as astronomical observation is one of the few areas of science where amateurs do original basic research. The sky at high magnification through a telescope such as many amateurs have is just so vast that the big professional telescopes can't hope to cover it all - so they rely on amateurs to fill the gaps.
Then, they'd share the news and compare notes - from many different countries world wide.
Nothing the governments could do - internet, telephones, letters, people traveling, one way or another they'd share the news.
MORE THAN TWO MONTHS WARNING
And for something as major as that - you'd have six months of warning at least even for a ten kilometer asteroid - we know all the ten kilometer asteroids inside of Jupiter's orbit. As for a hundred or thousand kilometer asteroid - we would spot it easily - out probably as far as Neptune, as we spot hundred kilometer scale objects beyond Neptune's orbit at 30 au nowadays. List of known trans-Neptunian objects. If bright, we spot even smaller ones out to that distance, here is 58534 Logos which is only 77 km in diameter and its perihelion is 39.675 AU, well beyond Neptune.
Any asteroid with aphelion beyond Neptune has to have a semi major axis at least half that of Neptune, at least 15 au, so must have orbital period of more than 58 years (by this calculator: Orbital period of a planet ) - 58534 Logos has an orbital period of 302.8 years - so if there was a hundred kilometer asteroid headed towards the inner solar system we'd discover it several decades before it got here.
But - again the cratering record shows - that that just isn't happening in our present solar system. Rare enough at least so that if it does happen, chance of hitting any planet is too minute to be significant.
So really more like smaller asteroids, say of the ten kilometer or scale. Small enough to be civilization threatening - but survivable with technology at least by some humans.
And on Earth also - no need to go into space, best place to ride it out is here where you have more resources to hand immediately after the disaster, a breathable air, water, reasonable temperature after the event, and you don't need a spaceship to return to Earth.
We'd probably have a year or more even in that case, even if on a cometary path direct to the sun - if it's as big as that.
After all we know about new first time comets entering our inner solar system well in advance - and they are far smaller than this.
NOT REMOTELY LIKELY FOR HUNDREDS OF MILLIONS OF YEARS
Actually this is not likely to happen for a few hundred million years. There's a chance that Mercury might be disturbed from its orbit and hit the Earth - very low probability - through repeated resonance with Jupiter.
Mercury (planet), diameter of just under 5000 km - it would cause human extinction if it hit Earth (unless we have people in space), probably melt our crust, like the impact that created the Moon. There is a tiny probability that it could hit the Earth hundreds of millions of years into the future, see Stability of the Solar System
But not for hundreds of millions of years yet.
Also we can tell by looking at impact craters on the Moon and on Mars also on Earth - nothing that big has hit any of them, or any of the other planets, since the very early days of the solar system, first few hundred million years, in the late heavy bombardment.
The big lunar seas and the very largest craters on the Moon - the largest ones, perhaps large enough to cause extinction of humans if they hit the Earth- these date from the https://en.wikipedia.org/wiki/La... which ended approximately 3.8 billion years ago.
We no longer get impacts that big - next likely chance of something like that - and probability low - is if Mercury gets disturbed from its orbit - or something cosmic such as another star passing close to our sun and disturbing the orbits of our planets - if that happens - it's many millions of years into our future.
WHAT COULD HAPPEN
What we could get is something like the impact that brought an end to the dinosaurs. A giant meteorite ten kilometers across, or a few tens of kilometers across.
That probably created a fire storm over the Earth for a short time at moment of impact, burnt all the vegetation - and followed by dense ash clouds cutting out light from the sun.
Many species went extinct then, for sure. But they didn't have our technology.
After an impact like that, there would be some humans survive the initial impact, e.g. in submarines or deep underground.
With as little as a few months warning we could make sure that some humans survive in underground and under sea shelters - and we would know which side of the Earth the impact would be - and which would be the safest places - and doubtless move the world population to the other side of the Earth (except for a few unwilling or can't be moved) - and do our best to shelter them also.
Something like this could survive deep under the sea and surface after the disaster.
A modern nuclear submarine can go to a depth of 1,600 feet where they'd survive almost anything happening on the surface. Submarine depth ratings
We wouldn't go extinct, I can't see that happening because of a meteorite impact.
And in any case, you are talking about something so unlikely - we'd be better off paying more attention to things that could happen - like Tsunami causing small impacts with objects a few hundred meters perhaps up to 1 km across - and to detect those as much as we possibly can - which we are already doing - and those surely can be diverted.
WHAT IF SOME FUTURE CIVILIZATION DOES NEED TO DIVERT MERCURY OR A HUNDREDS OR THOUSANDS OF KMS SCALE ASTEROID?
Diverting a 1000 km diameter asteroid would be very hard - and e.g. preventing Mercury from hitting Earth if that's what is predicted when the time comes a few hundred million years into the future - that would be hard.
But we'd know about it long in advance. With future technology, and complete survey of our solar system out to the Oort cloud - surely thousands, or millions of years in advance. And if we had a long lived stable civilization by then - able to do projects lasting for millennia and millions of years - they might be able to do something about that also.
But it's not our priority right now. And in very remote chance that we do see something that big and it's headed for Earth - even with our present day technology and amateur telescopes, we'd know months or years in advance and could find a way for a few people at least to survive on the Earth. So is time enough to start thinking about that if it ever happens, which is not likely.
And the governments of the time would just have to live with and deal with the situation that everyone knows about it. Nothing they can do about that.
Except of course - e.g. if a totalitarian government controlling all its news, restricting internet access, monitoring all phone calls, and opening all letters to its citizens - if it was as controlling as that - perhaps it could keep its own citizens in the dark - but so long as they have internet connection or telephone or free to travel, or able to read uncensored letters, or anything like that - then some of their citizens would learn about it and it just couldn't be contained after that.
In any case, the Earth's oceans might well boil before then, from the gradually warming sun - hundreds of millions of years into the future again. Also, bear in mind that it took 500 million years for humans to evolve from the first multi-cellular cell. Some microbe just starting on the steps to microcellularity has plenty of time to evolve to humans again or our equivalent before it is likely to happen. So, I think there are many things to be concerned about, but this is not one to put on our list of priorities.
GLOBAL WARMING
Human caused global warming in near term also can't get close to extinction causing for humans - worst temperature rise projection is something like 5C for 2100 - major humanitarian disaster, starvation, famine, instability - quite possibly collapse of governments - if all that happened - but not extinction of humans - that's just pure sci. fi.
Recent estimate, the runaway greenhouse effect to make Earth into a planet like Venus, for the temperature to keep going up, runaway effect, we'd need to burn at least ten times the amount of fossil fuel available in all known reserves on the Earth - Will Earth's Ocean Boil Away?
MAIN PROBLEMS TO BE CONCERNED ABOUT, OURSELVES
I think our main problems are ourselves. Especially things like biotech, nanotech, and increasing military capabilities and what those might do in long term future.
That's also the conclusion, for instance of an article for the Lifeboat Foundation - Safeguarding Humanity
See also Risking human extinction for an interesting perspective on this (I don't necessarily agree with the author, but it gets you thinking).
Which also means we have the capabilities to deal with them also - since we are the problem then we have to work on ourselves to find a solution.
Things like, for instance, taking great care and being serious about investigating any existential (extinction causing) risks of future technology as we develop it.
In the present I think one of the areas where we have to be very careful is in the study of XNA and creating of novel lifeforms in the laboratory. That's not just genetic modification - that also I think has to be done with care - not total prohibition, these technologies have a lot of potential to benefit humanity also and may be part of the solution to our problems - but responsibly, to investigate carefully and thoroughly.
But even more so - creating new forms of biochemistry in the laboratory - I think that needs great care. As do at least some of the researchers in the field.
But as for asteroid impacts - I think - not extinction causing threats to be concerned about - though definitely need to keep an eye on them.
Especially, should continue to search for the smaller impacts up to about one or two km or so diameter especially. And in process of searching for those, we would of course spot larger 10 km scale ones also in the very remote chance that any are headed our way.
From the cratering record, I'd be utterly astonished if we find any hundreds of kms or thousands of km size asteroid heading our way sooner than millions, probably hundreds of millions of years into the future.
UPDATE: WHAT ABOUT BIG ASTEROIDS LIKE CERES, VESTA, PALLAS ETC
Yes any of those would melt the crust and boil the oceans dry. Perhaps a few microbes would survive in the debris thrown into space to reestablish life on Earth when it cools down, but that would be about it.
But these big asteroids are all in a stable orbits, at least for millions of years.. Vesta, say, is no more going to hit Earth than Mercury or Mars.
And we can tell from the cratering record that nothing much larger than about 10 km has hit the inner solar system over the last three billion years - not on Mars, Earth, what we have of the history of Venus, Mercury, or the moons of Mars and our Moon. They all have big craters on them large enough to have made us extinct, but they are all well over three billion years old.
The reason seems to be due to Jupiter which catches, breaks up or diverts larger comets as they come into the inner solar system. And as for the ones already there, this did happen in the early solar system, but they are now in long term stable orbits and nothing like this has happened for billions of years.
For more about this see my Giant Asteroid Headed Your Way? - How We Can Detect And Deflect Them
Which is also available as a kindle booklet:
Giant Asteroid Is Headed Your Way? : How We Can Detect and Deflect Them (Amazon)