How did the Battle of Gettysburg help the union win the civil war?

General Robert Lee tried to invade the union with the battle of Gettysburg but it did not end good. The Confederacy was hurt badly. After this battle the South didnt try to invade the north again. Thus a reason for the union win.