Why Did the Battle of Gettysburg Start?

The battle of Gettysburg started because the Confederate army and the Union army came face to face just outside of town. The Confederates were trying to invade the north, and reach Harrisburg Pa, and the Union troops were defending.