The Gettysburg campaign was a military invasion of Pennsylvania by the main Confederate army under General Robert E. Lee in summer 1863. It was the first time during the war the Confederate Army attempted a full-scale invasion of a free state. The Union won a decisive victory at Gettysburg, July 1–3, with heavy casualties on both sides. Lee managed to escape back to Virginia with most of his army. It was a turning point in the American Civil War, with Lee increasingly pushed back toward Richmond until his surrender in April 1865. The Union Army of the Potomac was commanded by Maj. Gen. Joseph Hooker and then (from June 28) by Maj. Gen. George Meade.
After his victory in the Battle of Chancellorsville, Lee's Army of Northern Virginia moved north for a massive raid designed to obtain desperately needed supplies, to undermine civilian morale in the North, and to encourage anti-war elements. Lee's army slipped away from Federal contact at Fredericksburg, Virginia, on June 3, 1863. The largest predominantly cavalry battle of the war was fought at Brandy Station on June 9. The Confederates crossed the Blue Ridge Mountains and moved north through the Shenandoah Valley, capturing the Union garrison at Winchester, in the Second Battle of Winchester, June 13–15. Crossing the Potomac River, Lee's Second Corps advanced through Maryland and Pennsylvania, reaching the Susquehanna River and threatening the state capital of Harrisburg. However, the Army of the Potomac was in pursuit and had reached Frederick, Maryland, before Lee realized his opponent had crossed the Potomac. Lee moved swiftly to concentrate his army around the crossroads town of Gettysburg.