I'm certainly not well read on this period but
Gold was discovered in 1848. They kept it quiet till after the peace treaty was signed.
What if it got out?
With a POD this late not much really. The war was already underway and pretty much over. The US got what it wanted and the gold was an extra bonus.
Would Mexico have kept Cali? Were they in a position to do so? Would the war have reignited?
Once again this POD is too late. Could Mexico keep Cali? Certainly. An earlier Mex-American War (or one where Santa Anna doesn't take part in) would likely result with Mexico keeping California, or establishing the border at the 37th or 38th parallel (between Monterrey and San Francisco Bay). Thus splitting California in two. Before the War President Jose Joaquin Herrera (one of the few smart Mexican leaders of the time) actually proposed this border but was deposed for doing so by pro-Santa Anna generals.
If Mexico had kept Cali, would we still have had the Civil War?
How would the 19th century have played out if Mexico kept Cali?
Yes on the Civil War and probably earlier since the South would have no territory on which to expand slavery. Unless the US decides to expand on the Caribbean.
America would have took it over like they eventually took over Texas. Most of the people who went into California were and would have been US citizens. I doubt if Mexico would fight this time. They can't win. The question is how much the USA would have paid for the state or would California just started their own republic and asked to be part of the USA
However, unlike Texas most of the people reaching California would have been much more recent immigrants. And people from other parts of the world would also arrive. East Asia especially. A Mexican California would also have different immigration laws than OTL. After what happened with Texas Mexico would be quite wary of American immigration.
Also if it did declare independence. I find annexations somewhat unlikely. Even in OTL California was deemed to far to be governed. Annexing a California that already has a population and a fast growing identity of its own due to the population boom would be a situation very different from Texas. This doesn't mean the US won't try but it is quite a different situation.
Mexico was decisively defeated by 1848. American troops controlled New Mexico, California, much of NE Mexico, Veracruz, and Mexico City. Mexico had to make peace on almost any terms.
Yes, Mexico was soundly defeated in OTL. However changing this fate is not as hard as it seems. The US used a minimum number of troops in most of its operations. There were never more than 500 American troops in Alta California and Western New Mexico. Some tragedy befalling on them isn't hard.
The areas the US annexed in the Treaty of Guadelupe-Hidalgo where those areas when Mexican control was theoretical, not real. The inhabitants were mostly Indians who had no loyalty to Mexico City, with scattering of settlements of culturally Spanish/Mexican descent with varying loyalty to the government. In terms of real, current contributions to the country (instead of theoretical future benefits), Mexico could afford to give up their claims.
If California was known to have gold, maybe the Mexicans might have gotten the US to agree to pay more for the annexed land in the treaty, but only if the US feels like being generous.
That is not entirely true. While Mexico had little real control over those territories. There was a sizable population in Southern California and New Mexico by the time of the invasion. And in both places the US experienced an unexpected resistance from the local populations. The Taos Revolt (and others in New Mexico) were rather brutal on how such a small population resisted and many ended in massacres. While in Los Angeles the US had quite a hard time occupying the city.
Compare this to Puebla, where the local government declared neutrality welcomed the invaders and gave them free pass between Puebla and Cuernavaca and I would argue Mexico kept the wrong Mexicans.
The closer you were to the US border and father from Mexico City, the more loyal the populations were to Mexico, or rather the idea of Mexico (a free Catholic Republic). Remember that even the Republic of Rio Bravo never really intended to secede, they disliked Santa Anna and rebelled against him, and openly stated their intention to rejoin Mexico once the necessary Reforms had been made.
Closer to Mexico City people were more aware of the idiosyncrasies and idiocies of the central government and tended to be mostly loyal to their own state or town government.
Have to agree with Blackfox; 1848 is way too late. By that point, Mexico doesn't physically control California, and it has no negotiating leverage against the US. At best, the US pays a bit more for California in the final treaty. At worst, this change delays the negotiations, and gives Polk time to recall Nicholas Trist and send someone much more expansionist in his place.
A very likely outcome in this case.
But with an earlier POD, it is quite possible for Mexico to keep California. But you would need Mexico to reform many of its political aspects FAST. Real Fast.