Until the 1820s, the whole of Mexico including Texas which was then a part of Mexico, was ruled by Spain. But in the 1820s, Mexico gained independence and the Spanish rule ended. Texas was on the border of Mexico and United States of America.
To deal with the raids of the Native American tribes in Texas, the Mexican government encouraged settlers from USA to come to Texas and settle there. Before soon, the population of the white American settlers became more than the population of the native Mexicans.
In the 1830s, the Mexican government became worried about the large population of white Americans in Texas. So the government tried to exert more control over Texas. The white population didn’t like it and soon, armed conflict began between the two sides.
In 1836, a full-scale war began between Mexico and Texas. Mexican army was initially successful but in 1836, the Texans secure many victories. They even went on to officially declare their independence from Mexico. During the war, a large number of white American volunteers from USA traveled eastwards and joined the Texan armies. In the end, the Texans won and Mexico was forced to end its rule in Texas.
Once Texas was independent of the Mexican rule, it initially remained an independent republic. Although many Texan people wanted to join the United States of America, this union was delayed from the independence in 1836 until 1844. The main reason was that Texas was a slave state, where slavery was legal.
On the other side, USA was trying to decrease slavery in its own states and it didn’t want to allow another slave state to enter the union. But in 1844, US Congress finally agreed to make Texas a part of the Union. In this way, Texas officially became the 28th state of the United States of America.
Although Mexican rule in Texas had ended in the 1830s, Mexican government continued to claim that Texas was a part of Mexico. So when USA officially made Texas a part of the Union in 1844, the Mexicans became angry. Another issue was that the Mexicans claimed that even if Texas became separated, the land until the Nueces River was included within Mexican border. The Texans claimed that the Mexican territory ended at Rio Grande River. This finally resulted in another war.
In 1846, American government sent an army to enforce the Texan border, claiming all land until the Rio Grande River. The Mexican government also sent an army and a war started. The war continued until 1847. By 1847, the Mexican army had been defeated in many battles and the U.S. Army had reached Mexico City, the capital of Mexico.
With the loss of the city, Mexico was forced to end the war, give up the territories on the other side of Rio Grande River and also agreed to sell a large portion of land to USA for $15 million. All this was agreed as part of the Treaty of Guadalupe Hidalgo.