When American soldiers came to California, the Bear Flag Revolt was happening. Some Californians were trying to leave Mexico and to form their own country, as had happened in Texas. In July and August 1846, American soldiers captured Monterey, Yerba Buena, and Los Angeles. After a counterattack by the "Californios", the Americans had taken much of California by 1847. The Mexican governor of California, Pio Pico, left the state.