It all begins from a cloud of gas. When a cloud of molecular gas collapses under its own gravity, there are always a few regions that start off just a little bit denser than others. Every location with matter in it does its best to attract more and more matter towards it, but these overdense regions attract matter more efficiently than all the others. Because gravitational collapse is a runaway process, the more matter you attract to your vicinity, the faster additional matter accelerates to join you.