How and when did the Earth form geologically?

The oldest rocks from space are dated back to about 4.5 billion years ago, so this is around when our planet would have formed. The entire Solar System (which includes the Earth) arose when a giant cloud of gas and dust called a nebula began to collapse under its own gravity. This probably happened when, about five billion years ago, a nearby star exploded in a supernova, releasing a shockwave that caused the cloud to contract. Most of the gas gathered in the center to form the Sun, while the rest flattened out into a spinning disk.

The heavier, metallic elements existed closer to the Sun and would form the terrestrial planets. Through gravity, dust particles within the protoplanetary disk began to stick together, growing into pebbles, then boulders, then planetesimals. These chunks of rock collided with one another and clumped together to form larger and larger bodies. This is called accretion: when an object grows in size and mass by gravitationally collecting the material around it. Slowly, over millions of years, Earth formed by this process.

Our planet started out as a hot mass of scorched rock. Volcanic outgassing created the early atmosphere, but it contained almost no oxygen and would have been toxic to humans and most modern life. Much of the Earth was still molten because of extreme volcanism and frequent collisions with other bodies. One very big collision is thought to have been responsible for creating the Moon and tilting the Earth at an angle. Over time, such cosmic bombardments ceased, allowing our planet to cool and form a solid crust. Water that was brought here by comets and asteroids condensed into clouds and the oceans took shape. Earth was finally hospitable to life, and the earliest forms that arose enriched the atmosphere with oxygen.

See the links below for more information.
Earth was formed by collisions within the giant disc-shaped cloud of material. Gravity gathered the dust and gas together into clumps.