"Commodore John Drake Sloat ordered his naval forces to occupy Yerba Buena (present San Francisco) on July 7 and within days American forces controlled San Francisco, Sonoma, and Sutter's Fort in Sacramento.The treaty ending the Mexican–American War was signed on February 2, 1848, and Mexico formally ceded Alta California (including all of present-day northern California) to the United States.