Here is a general time line:
1849 CA Gold Rush begins
1850 CA enters the Union
1861 Civil War begins
1862 Pacific Rail Act Passed
1863 Construction of the Union Pacific building West and Central Pacific building East begins.
1865 Civil War ends.
1869 UP and CP rails joined at Promontory, Utah
The Pacific Rail Act was passed to keep CA and the state's wealth in the Union. It was really uncertain CA would remain in the Union if a rail line was not built.
Prior to the railroad there were three long and dangerous ways to get to CA.
1. Overland by walking, riding a horse or wagon train. Think of the Donner Party in this regard.
2. Ship to Panama and then walking, by horse or by wagon across the Isthmus and then ship to San Francisco. Many people caught tropical diseases during this trip and died. Others were caught in hurricanes and their ships sank.
3. Around Cape Horn by ship to San Francisco. The fastest clipper ships made it from New York in about 100 days. Most ships were much slower.
It has always surprised me how many people made these trips to seek their fortune in CA. Some people made this trip multiple times. I don't know this for a fact, but I think that the most popular route was across the Isthmus.
NH Joe