The U.S. state of West Virginia was formed out of western Virginia and added to the Union as a direct result of the American Civil War , in which it became the only modern state to have declared its independence from the Confederacy. In the summer of 1861, Union troops, which included a number of newly-formed Western Virginia regiments, under General George McClellan, drove off Confederate troops under General Robert E. Lee. This essentially freed Unionists in the north-western counties of Virginia to form a functioning government of their own as a result of the Wheeling Convention.
After Lee's departure, western Virginia continued to be a target of Confederate raids. Both the Confederate and state governments in Richmond refused to recognize the creation of the new state in 1863, and thus for the duration of the war the Confederacy regarded its own military offensives within West Virginia not as invasion but rather as an effort to liberate what it considered to be enemy-occupied territory administered by an illegitimate government in Wheeling. Nevertheless, due to its increasingly precarious military position and desperate shortage of resources, Confederate military actions in what it continued to regard as "western Virginia" focused less on reconquest as opposed to both on supplying the Confederate Army with provisions as well as attacking the vital Baltimore and Ohio Railroad that linked the northeast with the Midwest, as exemplified in the Jones-Imboden Raid. Guerrilla warfare also gripped the new state, especially in the Allegheny Mountain counties to the east, where loyalties were much more divided than in the solidly Unionist northwest part of the state. Despite this, the Confederacy was never able to seriously threaten the Unionists' overall control of West Virginia.