I have long wondered why Lee decided to attack the fortified Union line at Gettysburg on Days 2 and 3. He had, after all, previously witnessed the carnage imposed on infantry assaulting fortified lines, in battles such as Malvern Hill, Fredericksburg and Second Manassas. Military historians claim that his objective on both days was to penetrate the Union line, roll it up and drive the Union Army off the field. Yet even if successful, the human cost of such an attack would have made any further operations after the battle difficult, if not impossible. Longstreet claims in his memoirs that prior to the invasion of Pennsylvania, he obtained Lee's agreement to stand on the tactical defensive when they encountered the Union Army, but this is clearly not what happened. It just doesn't make sense!
Back to the actual topic of the thread. As pointed out, the Union position wasn't fortified.
On July 1 Lee enjoyed a great victory, defeating and nearly destroying two corps of the Army of the Potomac and forcing a retreat through the town onto Cemetery Hill. This came almost two months after his victory at Chancellorsville.
On July 2, Lee had the following choices:
1. Retreat
2. Maneuver
3. Stay in place
4. Attack
He considered each alternative carefully and came to the logical decision that attack was his best option. He was trying to win the war, after all, and a retreat would not do that. Maneuvering without cavalry was too dangerous. Staying in place was dangerous as well, since the Union Army was getting stronger with time while he was not going to get any stronger. Attack, then, was his best option for July 2.
On that day, he came very close to winning. The Union line was almost broken in several places, and only the last second arrival of new troops in various places was able to stave off Union defeat.
On July 3, he had the same options:
1. Retreat
2. Maneuver
3. Stay in place
4. Attack.
Again, he considered each alternative carefully.
Retreat would not help him win the war.
He now had Stuart's cavalry to help with maneuver, but he needed to know what road system he would use, which he didn't know and didn't have time to find out.
He still would not get any stronger by staying in place, while Union reinforcements were still coming and the Union force would continue to get stronger. Additionally, his foraging was now limited, having cleaned out the area where he was. Staying there much longer would not do.
So he decided once again, logically, that attack was his best option, remembering his men had broken the Union line two days before and had almost broken the Union line again in several places the day before.