It is believed that the force of repulsion expanding the universe is due to dark energy, i.e. the energy of the vacuum, which is anti-gravitational. This is the force which is pushing the galaxies apart. However, if galaxies are close together, their local gravity can overcome this repulsion.