Asteroids and comets that are in orbits which carry them close to the Earth at some time are called near-Earth objects (NEOs). NASA is charged by Congress with the mission to investigate NEOs and coordinate an assessment of the threat they pose to the Earth.
NEOs impact the earth all the time. Most are very small objects which burn up when the enter the atmosphere. About every six months one NEO burns up in the atmosphere releasing as much energy as a 100 kiloton explosive. These events are routinely detected by the sensors that are used to monitor the atmosphere for nuclear explosions.
NASA funds an ongoing program to identify every large NEO and plot their orbits. One objective is to detect any object that will impact the Earth twenty years before the impact date.
There is some debate about what to do about NEOs that are expected to impact the Earth. One option is to develop some scheme to alter the orbit of the NEO. As Earth moves through its own diameter every six minutes, the arrival time of the NEO would only have to be changed by six minutes for it to entirely miss the Earth. The general consensus is that we can work on a solution once we have detected an NEO on collision course, since we will have 20 years to react.