It's true!! Jupiter does protect the earth from the attack of various comets by diverting them to a different direction or catching them in its orbit. If those comets were to reach earth, it would be impossible for life to sustain.
As per Indian mythology, 9 people represented the 9 planets. In ancient Hindu literature, Brihaspati is a Vedic-era sage who counsels the gods, while in some medieval texts the word refers to the largest planet of our solar system, Jupiter. Brihaspati is a Sanskrit word meaning Spati of Briha, the spirit of the vastness of the universe written as Brihaspati.
A story goes, Asuras or the demons were planning an attack and capture Heaven. The king of Heaven Indra was carelessly indulged in the pleasure of drinking and enjoying with the celestial nymphs. Brihaspati, being the royal teacher in heaven, the teacher of Indra himself, and a counselor of gods reaches Indra to warn him about the attack and help him with a plan to save the heaven and other gods. Indra being irrational, irresponsible, paranoid, and frenzied insulted Brihaspati and asked him to leave heaven. Ganga tried to warn Indra by letting him know of his mistake of insulting Brihaspati, who she called the oldest and the largest pillar of the system as he protects the earth and heaven with his vast knowledge. Indra insulted Ganga and asked her to leave heaven too. When demons attacked heaven, Indra was terrified and had no option but to flee. All gods, including the Trinity Gods, blamed Indra for the loss of heaven and Shiva punished him by taking away all his powers and sent him in exile.
In other planetary systems, it is evident that giant planets like Jupiter migrate from their original position to an orbit that is closer to their stars. When these giants move towards their stars, any small planets that stand in the way can be destroyed or may fling out of the star system altogether due to their strong gravity.
But Jupiter remains distant from the Sun. It serves as the gatekeeper to the solar system. Jupiter protects the other fellow planets, allowing them to maintain nearly circular orbits that provide stable climates over periods of time.
Not only that, Jupiter eats up any asteroid or comet that ventures near-earth protecting the earth from a possible extinction-causing collision.
While Jupiter often protects Earth and the other inner planets by deflecting comets and astroids, sometimes it sends objects on a collision course straight towards the Earth and other planets. Earlier in the solar system's history, where there were more objects flying around, the increased amount of impacts would have brought to Earth water and other ingredients to create life. Of course, other collisions would have been disastrous, such as the impact that likely led to the extinction of the dinosaurs 65 million years ago.
Fun fact: Jupiter is a 'Failed Star'
The giant is virtually made of 90% hydrogen and 10% helium, which's mighty close to the Sun's composition. In fact, some consider Jupiter to be a failed star. Jupiter is already a big boy, but if it were roughly 80 times bigger than it already is, it could have collapsed under its own gravity to form a star.
Jupiter doesn't really orbit the Sun. It orbits a point near the Sun which is called Barycenter.