While no one knows for certain how the Earth formed, scientists theorize that it formed over 4 million years ago after the sun went through its initial formation, gravity began to draw heavy particles together into a planet and solar winds blew away lighter gases. These heavy particles became the core of the planet. As the mass continued to grow, heavier particles sank to the center, according to Space.com.
As the Earth was forming, an object from space struck the new planet, causing particles to fly into space. Gravity pulled the particles together to form the moon. The remains of the object joined with the Earth to increase its overall size. Subduction in the Earth's mantle caused the formation of tectonic plates. These same forces caused the plates to divide and form the continents.
Earth's first atmosphere was blown away by solar winds. A second atmosphere formed from outgassing of the elements that formed the core. This second atmosphere included water vapor, nitrogen, carbon dioxide and other gases. The cooling cycle resulted in the formation of rain, leading to the development of oceans. This atmosphere was also instrumental in the development of life on the planet, according to Wikipedia. As life developed, the atmosphere changed again, due to the release of oxygen through photosynthesis.