A timeline of events for the Confederate Army after losing the Battle of Gettysburg
The Confederate Army of Northern Virginia began its Retreat from Gettysburg on July 4, 1863. Following General Robert E. Lee's failure to defeat the Union Army at the Battle of Gettysburg (July 1–3, 1863), he ordered a retreat through Maryland and over the Potomac River to relative safety in Virginia. 
The Union Army of the Potomac, commanded by Maj. Gen. George G. Meade, was unable to maneuver quickly enough to launch a significant attack on the Confederates, who crossed the river on the night of July 13 into South Mountain through Cashtown in a wagon train that extended for 15–20 miles, enduring harsh weather, treacherous roads, and enemy cavalry raids. The bulk of Lee's infantry departed through Fairfield in Pennsylvania and through the Monterey Pass toward Hagerstown, Maryland. Reaching the Potomac River, they found that rising waters and destroyed pontoon bridges prevented their immediate crossing. Erecting substantial defensive works, they awaited the arrival of the Union army, which had been pursuing over longer roads more to the south of Lee's route. Before Meade could perform adequate reconnaissance and attack the Confederate fortifications, Lee's army escaped across fords and a hastily rebuilt bridge.
Combat operations, primarily cavalry battles, raids, and skirmishes, occurred during the retreat at Fairfield (July 3), Monterey Pass (July 4–5), Smithsburg (July 5), Hagerstown (July 6 and 12), Boonsboro (July 8), Funkstown (July 7 and 10), and around Williamsport and Falling Waters (July 6–14). Additional clashes after the armies crossed the Potomac occurred at Shepherdstown (July 16) and Manassas Gap (July 23) in Virginia, ending the Gettysburg campaign of June and July 1863.
Background.
Military situation.
The culmination of the three-day Battle of Gettysburg was the massive infantry assault known as Pickett's Charge, in which the Confederate attack against the center of the Union line on Cemetery Ridge was repulsed with significant losses. The Confederates returned to their positions on Seminary Ridge and prepared to receive a counterattack. When the Union attack had not occurred by the evening of July 4, Lee realized that he could accomplish nothing more in his Gettysburg campaign and that he had to return his battered army to Virginia. His ability to supply his army by living off the Pennsylvania countryside was now significantly reduced and the Union could easily bring up additional reinforcements as time passed, whereas he could not. Brig. Gen. William N. Pendleton, Lee's artillery chief, reported to him that all of his long-range artillery ammunition had been expended and there were no early prospects for resupply. However, despite casualties of over 20,000 officers and men, including a number of senior officers, the morale of Lee's army remained high and their respect for the commanding general was not diminished by their reverses.
Lee began his preparations for retreat on the night of July 3, following a council of war with some of his subordinate commanders. He consolidated his lines by pulling Lt. Gen. Richard S. Ewell's Second Corps from the Culp's Hill area back through the town of Gettysburg and onto Oak Ridge and Seminary Ridge. His men constructed breastworks and rifle pits that extended 2.5 miles from the Mummasburg Road to the Emmitsburg Road. He decided to send his long train of wagons carrying equipment and supplies, which had been captured in great quantities throughout the campaign, to the rear as quickly as possible, in advance of the infantry. The wagon train included ambulances with his 8,000 wounded men who were fit to travel, as well as some of the key general officers who were severely wounded, but too important to be abandoned. The great bulk of the Confederate wounded—over 6,800 men—remained behind to be treated in Union field hospitals and by a few of Lee's surgeons selected to stay with them.
There were two routes the army could take over South Mountain to the Cumberland Valley (the name given to the Shenandoah Valley in Maryland and Pennsylvania), from where it would march south to cross the Potomac at Williamsport, Maryland: the Chambersburg Pike, which passed through Cashtown in the direction of Chambersburg, and; the shorter route through Fairfield and over Monterey Pass to Hagerstown. Fortunately for the Confederate army, it now had its full complement of cavalry available for reconnaissance and screening activities, a capability it lacked earlier in the campaign while its commander, Maj. Gen. J.E.B. Stuart, was separated from the army with his three best cavalry brigades on "Stuart's ride".
Unfortunately for the Confederate Army, however, once they reached the Potomac they would find it difficult to cross. Torrential rains that started on July 4 flooded the river at Williamsport, making fording impossible. Four miles downstream at Falling Waters, Union cavalry dispatched from Harpers Ferry by Maj. Gen. William H. French destroyed Lee's lightly guarded pontoon bridge on July 4. The only way to cross the river was a small ferry at Williamsport. The Confederates could potentially be trapped, forced to defend themselves against Meade with their backs to the river.
Opposing forces.
The Union Army of the Potomac and the Confederate Army of Northern Virginia retained their general organizations with which they fought at the Battle of Gettysburg. By July 10, some of the Union battle losses had been replaced and Meade's army stood at about 80,000 men. The Confederates received no reinforcements during the campaign and had only about 50,000 men available.
Union.
The Army of the Potomac had significant changes in general officer assignments because of its battle losses. Meade's chief of staff, Maj. Gen. Daniel Butterfield, was wounded on July 3 and was replaced on July 8 by Maj. Gen. Andrew A. Humphreys; Brig. Gen. Henry Price replaced Humphreys in command of his old division of the III Corps. Maj. Gen. John F. Reynolds, killed on July 1, was replaced by Maj. Gen. John Newton of the VI Corps. Maj. Gen. Winfield Scott Hancock of the II Corps, wounded on July 3, was replaced by Brig. Gen. William Hays. Maj. Gen. William H. French, who had temporarily commanded the garrison at Harpers Ferry for most of the campaign, replaced the wounded Daniel Sickles in command of the III Corps on July 7. In addition to the battle losses, Meade's army was plagued by a condition that persisted during the war, the departure of men and regiments whose enlistments had expired, which took effect even in the midst of an active campaign. To make matters worse, thousands of Union soldiers who had not eaten since the battle began would have to be fed while boots, forage and shoes for the Army's horses and mules needed to be replenished to pursue Lee's army. On the plus side, however, Meade had available temporary, although inexperienced, reinforcements of about 10,000 men who had been with General French at Maryland Heights, which were incorporated into the I Corps and III Corps. The net effect of expiring enlistments and reinforcements added about 6,000 men to the Army of the Potomac. Including the forces around Harpers Ferry, Maryland Heights, and the South Mountain passes, by July 14 between 11,000 and 12,000 men had been added the army, although Meade had extreme doubts about the combat effectiveness of these troops. 
In addition to the Army of the Potomac, Maj. Gen. Darius N. Couch of the Department of the Susquehanna had 7,600 men at Waynesboro, 11,000 at Chambersburg, and 6,700 at Mercersburg. These were emergency troops that were hastily raised during Lee's march into Pennsylvania and were subject to Meade's orders. In addition, a force of about 6,000 from the newly created Department of West Virginia under Brig. Gen. Benjamin Franklin Kelley sat astride the Baltimore and Ohio Railroad at Grafton, and New Creek in West Virginia, to prevent Confederate forces from retreating west, and later assisting in the pursuit of Lee toward Virginia.
Confederate.
Lee's Army of Northern Virginia retained its corps organization and commanders, although a number of key subordinate generals were killed or mortally wounded (Lewis Armistead, Richard B. Garnett, Isaac E. Avery, and William Barksdale), captured (James L. Kemper and James J. Archer), or severely wounded (John Bell Hood, Wade Hampton, George T. Anderson, Dorsey Pender, and Alfred M. Scales).
Imboden's wagon train.
At 1 a.m. on July 4, Lee summoned to his headquarters Brig. Gen. John D. Imboden, one of Stuart's cavalry brigade commanders, to manage the passage of the majority of the trains to the rear. Imboden's command of 2,100 cavalrymen had not played much of a role in the campaign up until this time, and had not been selected by Stuart for his ride around the Union Army. Lee and Stuart had a poor opinion of Imboden's brigade, considering it "indifferently disciplined and inefficiently directed," but it was effective for assignments such as guard duty or fighting militia. Lee reinforced Imboden's single artillery battery with five additional batteries borrowed from his infantry corps and directed Stuart to assign the brigades of Brig. Gen. Fitzhugh Lee and Wade Hampton (now commanded by Col. Laurence S. Baker) to protect the flanks and rear of Imboden's column. Imboden's orders were to depart Cashtown on the evening of July 4, turn south at Greenwood, avoiding Chambersburg, take the direct road to Williamsport to ford across the Potomac, and escort the train as far as Martinsburg. Then, Imboden's command would return to Hagerstown to guard the retreat route for the remainder of the army.
Imboden's train consisted of hundreds of wagons, which extended 15–20 miles along the narrow roads. Assembling these wagons into a marching column, arranging their escorts, loading supplies, and accounting for the wounded took until late afternoon on July 5. Imboden himself left Cashtown around 8 p.m. to join the head of his column. The journey was one of extreme misery, conducted during the torrential rains that began on July 4, in which the wounded men were forced to endure the weather and the rough roads in wagons without suspensions. Imboden's orders required that he not stop until he reached his destination, which meant that wagons breaking down were left behind. Some critically wounded men were left behind on the roadsides as well, hoping that local civilians would find and take care of them. The train was harassed throughout its march. At dawn on July 5, civilians in Greencastle ambushed the train with axes, attacking the wheels of the wagons, until they were driven off. That afternoon at Cunningham's Cross Roads (current day Cearfoss, Maryland), Capt. Abram Jones led 200 troopers of the 1st New York Cavalry and 12th Pennsylvania Cavalry in attacking the column, capturing 134 wagons, 600 horses and mules, and 645 prisoners, about half of whom were wounded. These losses so angered Stuart that he demanded a court of inquiry to investigate.
Fairfield and Monterey Pass.
After dark on July 4, Hill's Third Corps headed out onto the Fairfield Road, followed by Lt. Gen. James Longstreet's First Corps and Richard S. Ewell's Second Corps. Lee accompanied Hill at the head of the column. He ordered Stuart to post Col. John R. Chambliss's and Brig. Gen. Albert G. Jenkins's brigades (the latter commanded by Col. Milton Ferguson) to cover his left rear from Emmitsburg. Departing in the dark, Lee had the advantage of getting several hours head start and the route from the west side of the battlefield to Williamsport was about half as long as the ones available to the Army of the Potomac.
Meade was reluctant to begin an immediate pursuit because he was unsure whether Lee intended to attack again and his orders continued that he was required to protect the cities of Baltimore and Washington, D.C. Since Meade believed that the Confederates had well fortified the South Mountain passes, he decided he would pursue Lee on the east side of the mountains, conduct forced marches to quickly seize the passes west of Frederick, Maryland, and threaten Lee's left flank as he retreated up the Cumberland Valley. However, Meade's assumption was wrong—Fairfield was lightly held by only two small cavalry brigades and the passes over South Mountain were not fortified. If Meade had secured Fairfield, Lee's army would have been forced to either fight its way through Fairfield while its rear was exposed to the Army of the Potomac at Gettysburg or to take his entire army through the Cashtown Pass, a much more difficult route to Hagerstown.
On July 3, while Pickett's Charge was underway,