After having many battles in the south, Robert E. Lee wanted to move north, because the south had been hurt very badly from all of the battles. He decided to go up around Pennsylvania.
Robert E. Lee had a calvary leader, J.E.B. Stuart. Stuart was going to be Lee's "eyes." He would go around and see where they were, because Lee was from Virginia, and didn't know much about Pennsylvania. However, Stuart didn't do what he was supposed to. He went on raids instead, so Lee only got his information about where he was from a spy.
The Union Army followed. They had a new general now, George Meade. George Meade made sure the Union stayed to the right of the C.S.A. Why was this? It was because Washington D.C. was to the right, and they did not want the Confederates to invade Washington D.C., where the U.S. president and government were. If you look on the map of Gettysburg, you can see that there are many roads leading to Gettysburg. So, the troops ended up in Gettysburg.