The Army of the Shenandoah originated with the various militia and volunteer companies sent to seize and defend the town of Harpers Ferry, Virginia. To organize and train the companies, Virginia state commander Robert E. Lee initially appointed Thomas J. Jackson to command the post. Jackson formed five regiments of infantry and a battery of artillery from the various companies, forming the basis of the Stonewall Brigade. On May 15, Joseph E. Johnston replaced Jackson as commander of Harpers Ferry and continued to receive additional regiments from throughout the Confederacy. He would eventually have four brigades of infantry and an independent regiment of cavalry, the 1st Virginia Cavalry commanded by J. E. B. Stuart. In mid-June, forces from the UnionDepartment of Pennsylvania commanded by Robert Patterson began moving south towards Harpers Ferry. Fearing that the terrain around the town made it indefensible, Johnston had the bridges and as much equipment in the town as possible destroyed and retreated south to Winchester; Patterson remained along the Potomac River rather than pursue Johnston. Over the next few weeks, both forces watched each other, only engaging in battle once at Falling Waters on July 2. After spending almost two weeks waiting on the Potomac and receiving reinforcements, Patterson started advancing towards Winchester but had moved only before encountering Stuart's regiment screening Johnston's army. Patterson halted again and consulted his officers, who advised caution; this advice, along with the refusal of several regiments which were due for mustering out to remain any longer, convinced Patterson to cancel the advance. This allowed Johnston to follow orders he received on July 18 to transfer his army to reinforce P. G. T. Beauregard's Army of the Potomac at Manassas Junction. The movement started that evening, with each brigade marching to Piedmont where it boarded a train for Manassas Junction. Since there was only one train on the Manassas Gap Railroad, the brigades arrived one at a time; the artillery and cavalry marched overland. The final units of Johnston's army arrived on the afternoon of July 21. Since he was senior to Beauregard, Johnston had command over the two armies present. Before Johnston arrived at Manassas, Beauregard had drawn up plans for an attack on the Union army of Irvin McDowell across Bull Run on July 21, using brigades from both armies, and Johnston approved the plan, allowing Beauregard to issue the necessary orders in his name. However, the orders were vague and contradictory, which confused the brigade commanders and prevented the attack from taking place. On the morning of July 21, McDowell launched his own attack on the Confederate left wing, defended by one of Beauregard's brigades. As the battle escalated in the area of Matthews Hill and Henry House Hill, additional Confederate brigades were moved to the left flank. Eventually, all four of Johnston's brigades and four out of Beauregard's eight brigades were engaged in this area. It was while defending Henry House Hill that Jackson received his nickname of "Stonewall", which also became the name of his brigade. After the battle Johnston's and Beauregard's commands were consolidated into the Department of Northern Virginia, with their merged army using the name "Army of the Potomac"; Johnston retained command of the army, with Beauregard remaining as second in command until his transfer to the western theater.