I believe that you are asking how the battle started. If so, this is how the battle started.
The Confederate army in the summer of 1863 invaded the North for the second and last time. Initial plans were to attack Harrisburg, Pennsylvania and drive through to Philadelphia. If this was done, it would place Washington D.C. in severe threat of being seized by the Confederate Army. However, this plan of attack was not the only reason that the Confederate army invaded the North. Being that most of the battle of eastern part of the Civil War occurred in Virginia, Lee tried to move the destruction of war out of Virginia by placing the threat of attacks on the cities of Pennsylvania and inherently placing Washington D.C. as well. Lee knew that the Union army could not and would not let the invasion by the Confederate army go without being followed. Lee wanted to draw the armies out of Virginia so that the state could have some time to recover from the already substantial damaged that it had sustained, while at the same time, moving northward would allow the Confederate army to regain supplies for the army, including shoes, food, etc. The Confederate army was spotted in a town north of Gettysburg, Pennsylvania by the cavalry unit under General John Buford. Buford decided to hold this enemy off by dismounting his cavalry men and fighting like infantry. Buford only had a small amount of troops and could not hold off infantry for long, so he called for reinforcements of the Union 1st Corps under a Pennsylvanian named John F. Reynolds. Heth’s brigade of the Confederate army was the first to enter the field with instruction not to engage the Union army. Not knowing that Buford’s troops were dismounted cavalry and thinking that it was only the state militia, the Battle of Gettysburg began with the engagement of Heth’s brigade and Buford’s cavalry.
The Battle of Gettysburg (July 1–3, 1863), fought in and around the town of Gettysburg, Pennsylvania, as part of the Gettysburg Campaign, was the battle with the largest number of casualties in the American Civil War[4] and is frequently cited as the war’s turning point.[5] Union Maj. Gen. George Gordon Meade’s Army of the Potomac defeated attacks by Confederate Gen. Robert E. Lee’s Army of Northern Virginia, ending Lee’s invasion of the North.
Following his success at Chancellorsville in May 1863, Lee led his army through the Shenandoah Valley for his second invasion of the North, hoping to reach as far as Harrisburg, Pennsylvania, or even Philadelphia, and to influence Northern politicians to give up their prosecution of the war. Prodded by President Abraham Lincoln, Maj. Gen. Joseph Hooker moved his army in pursuit, but was relieved just three days before the battle and replaced by Meade.
The two armies began to collide at Gettysburg on July 1, 1863, as Lee urgently concentrated his forces there. Low ridges to the northwest of town were defended initially by a Union cavalry division, which was soon reinforced with two corps of Union infantry. However, two large Confederate corps assaulted them from the northwest and north, collapsing the hastily developed Union lines, sending the defenders retreating through the streets of town to the hills just to the south.
On the second day of battle, most of both armies had assembled. The Union line was laid out in a defensive formation resembling a fishhook. Lee launched a heavy assault on the Union left flank, and fierce fighting raged at Little Round Top, the Wheatfield, Devil’s Den, and the Peach Orchard. On the Union right, demonstrations escalated into full-scale assaults on Culp’s Hill and Cemetery Hill. Across the battlefield, despite significant losses, the Union defenders held their lines.
On the third day of battle, July 3, fighting resumed on Culp’s Hill, and cavalry battles raged to the east and south, but the main event was a dramatic infantry assault by 12,500 Confederates against the center of the Union line on Cemetery Ridge. Pickett’s Charge was repulsed by Union rifle and artillery fire at great losses to the Confederate army. Lee led his army on a torturous retreat back to Virginia. Between 46,000 and 51,000 Americans were casualties in the three-day battle. That November, President Lincoln used the dedication ceremony for the Gettysburg National Cemetery to honor the fallen and redefine the purpose of the war in his historic Gettysburg Address.