Galaxies are the basic unit of cosmology. They contain stars, gas, dust and alot of dark matter. They are the only `signposts' from here to the edge of the Universe and contain the fossil clues to this earlier time.
The physics of galaxy formation is complicated because it deals with the dynamics of stars (gravitational interaction), thermodynamics of gas and energy production of stars. For example, stars form from gas clouds, but new stars heat these clouds, which dissipates them and stops the formation of other stars.
After recombination, density enhancements either grew or dispersed. According to our hybrid top-down/bottom-up scenario, an assortment of enhancements formed of various sizes. Small, dense ones collapsed first, large ones formed slower and fragmented as they collapsed.
The first lumps that broke free of the Universe's expansion were mostly dark matter and some neutral hydrogen with a dash of helium. Once this object begins to collapse under its own gravity, it is called a protogalaxy. The first protogalaxies appeared about 14 billion years ago.
Note that dark matter and ordinary matter (in the form of hydrogen and helium gas at this time) separate at this time. Gas can dissipate its energy through collisions. The atoms in the gas collide and heat up, the heat is radiated in the infrared (light) and the result is the gas loses energy, moves slowly = collapses to the center. Dark matter does not interact this way and continues to orbit in the halo.
Even though there are no stars yet, protogalaxies should be detectable by their infrared emission (i.e. their heat). However, they are very faint and very far away (long time ago), so our technology has not been successful in discovering any at this time.
Formation of the First Stars :
As the gas in the protogalaxy loses energy, its density goes up. Gas clouds form and move around in the protogalaxy on orbits. When two clouds collide, the gas is compressed into a shock front.
The first stars in a galaxy form in this manner. With the production of its first photons by thermonuclear fusion, the galaxy becomes a primeval galaxy.
Star formation sites in primeval galaxies are similar to star forming regions in present-day galaxies. A grouping of young stars embedded in a cloud of heated gas. The gas will eventually be pushed away from the stars to leave a star cluster.
The first stars in our Galaxy are the globular star clusters orbiting outside the stellar disk which contains the spiral arms. Most galaxies with current star formation have an underlying distribution of old stars from the first epoch of star formation 14 billion years ago.
Stellar Death :
The most massive stars end their lives as supernova, the explosive destruction of a star. Supernova's occur when a star uses up its interior fuel of hydrogen and collapses under its own weight. The infalling hydrogen from the star's outer envelope hits the core and ignites explosively.
During the explosion, runaway fusion occurs and all the elements in the periodic table past lithium are produced. This is the only method of producing the heavy elements and is the origin to all the elements in your body.
This shell of enriched gas is ejected into the galaxy's gas supply. Thus, the older a galaxy, the more rich its gas is in heavy elements, a process called chemical evolution.
Ellipticals vs. Spirals :
The two most distinct galaxy types are ellipticals and spirals. Ellipticals have no ongoing star formation today, spirals have alot. Assuming that ellipticals and spirals are made from the same density enhancements at the time of recombination, why did they evolve into very difference appearances and star formation rates?
The answer is how rapid their initial star formation was when they formed. If star formation proceeds slowly, the gas undergoes collisions and conservation of angular momentum forms a disk (a spiral). If star formation is rapid and all the gas is used up in an initial burst, the galaxy forms as a smooth round shape, an elliptical.
Gas falling into a spiral disk is slowed by collisions and star formation continues till today. The spiral arms and patterns are due to ongoing star formation, whereas ellipticals used all their gas supplies in an initial burst 14 billion years ago and now have no ongoing star formation.
Galaxy Mergers/Interactions :
After their formation, galaxies can still change their appearance and star formation rates by interactions with other galaxies. Galaxies orbit each on in clusters. Those orbits can sometimes cause two galaxies to pass quite close to each other to produce interesting results.
Solid objects, like planets, can pass near each other with no visible effects. However, galaxies are not solid, and can undergo inelastic collisions, which means some of the energy of the collision is transfered internally to the stars and gas in each galaxy.
The tidal forces will often induce star formation and distort the spiral pattern in both galaxies.
If enough energy is transfered internally to the stars, then galaxies may merge. Galaxy mergers are most frequent in dense environments, such as galaxy clusters.