We really don't know how various galaxies formed and took the many shapes that we see today. But we do have some ideas about their origins and evolution.
Let's look at the period of galaxy formation.

Edwin Hubble's observations, and subsequent Hubble Law (which we'll explain later), led to the idea that the universe is expanding. We can estimate the age of the universe based on the rate of expansion. Because some galaxies are billions of light years away from us, we can discern that they formed fairly soon after the big bang (as you look deeper into space, you see further back in time). Most galaxies formed early, but data from NASA's Galaxy Explorer (GALEX) telescope indicate that some new galaxies have formed relatively recently -- within the past few billion years.
Most theories about the early universe make two assumptions:
From these assumptions, astronomers believe that the denser areas slowed the expansion slightly, allowing gas to accumulate in small protogalactic clouds. In these clouds, gravity caused the gas and dust to collapse and form stars. These stars burned out quickly and became globular clusters, but gravity continued to collapse the clouds. As the clouds collapsed, they formed rotating disks. The rotating disks attracted more gas and dust with gravity and formed galactic disks. Inside the galactic disk, new stars formed. What remained on the outskirts of the original cloud were globular clusters and the halo composed of gas, dust and dark matter.
Two factors from this process might account for the differences between elliptical and spiral galaxies:

Galaxies do not act alone. The distances between galaxies do seem large, but the diameters of galaxies are also large. Compared to stars, galaxies are relatively close to one another. They can interact and, more importantly, collide. When galaxies collide, they actually pass through one another -- the stars inside don't run into one another because of the enormous interstellar distances. But collisions do tend to distort a galaxy's shape. Computer models show that collisions between spiral galaxies tend to make elliptical ones (so, spiral galaxies probably haven't been involved in any collisions). Scientists estimate that as many as half of all galaxies have been involved in some sort of collision.
Gravitational interactions between colliding galaxies could cause several things:
More Options: