There are two different aspects of your question.
If you are asking about the process of Earth formation, Earth was formed due to gravitational collapse of the interstellar dust that filled the Sun orbit in the early stages of solar system formation. At the beginning, before even our Sun existed the space was filled with gases (mostly hydrogen) and dust. Because every mass exerts a small gravitational force on other mass, a large part of this matter collapsed together and formed our star, the Sun. However, a small part of this matter remained in orbit around the Sun and it further collapsed to form the planets.
If you are asking about the reaction where the chemical elements found on Earth were formed, then the answer is that they were formed by the fusion process in a previous existent star. Fusion is a nuclear process in which 2 nuclei collide and give a 3rd heavier nucleus. It begins with 2 nuclei of Hydrogen giving a nucleus of Helium, and continues with heavier and heavier nuclei.
If the star is old enough and big enough, it explodes (forms a Supernova) and all its formed matter scatter into space. This matter collapses again and newer star systems are formed. In regular stars only chemical elements until Fe are formed, the other heavier elements being formed only when a Supernova explodes (there are necessary bigger collision forces for the elements that transcend Fe to be formed).