The initial formation of galaxies is primarily explained by the gravitational collapse of massive gas and dust clouds. According to current theories of galaxy evolution, such as the Lambda Cold Dark Matter (ΛCDM) model, the key factor in galaxy formation is the gravitational pull that leads to the collapse of these clouds to form stars and, subsequently, galaxies.
Specifically, small particles of gas and dust come together under the influence of gravity to form larger structures. As these clumps merge and aggregate, they form the proto-galactic structures from which galaxies develop. This process involves a combination of gravitational attraction and the cooling of the gas, allowing it to clump together and eventually form stars.
While the interactions and collisions of stars can play a significant role in shaping existing galaxies and influencing their evolution over time, the initial formation of galaxies is fundamentally driven by the gravitational collapse of gas and dust.