The Battle of Gettysburg occurred as a result of General Robert E. Lee's push north into Pennsylvania in an attempt to move the bulk of the fighting in the east away from Virginia and into Union territory. His ultimate goal was Philadelphia, but General George Meade's forces caught up with him at Gettysburg. Both sides arrayed their forces around the small town, and the bloodiest battle of the war began.
On the first day of the battle, Confederate forces were situated north of the town of Gettysburg, and the Union forces approached from the south. The Union troops initially occupied positions north of the town, but fell back under an attack from a numerically superior force. They ended up taking positions around Cemetery Hill and Cemetery Ridge, where they were able to hold out until reinforcements arrived.
On the second day of fighting, Lee attempted to flank and envelop the Union position, but faulty intelligence led his forces to crash directly into Union troops that had redeployed to a more suitable position. Arriving reinforcements helped the Union forces hold their positions, although casualties on both sides were high.
On the third day, one of the most famous military maneuvers of the war occurred. Forces under General George Pickett attempted to take Cemetery Ridge in one of the most ill-conceived attacks of the war. His forces were subjected to withering fire from well-prepared Union troops and collapsed, suffering devastating casualties. As it became clear the Confederates could not dislodge the Union forces, they withdrew, ending Lee's last attempt to bring the war into Union territory.