close to 50,000 union and confederate troops were killed or wounded at the battle of gettysburg on july 1-3 , 1863 , when the army of the potomac turned back the army of northern virginia 's attempt to invade the north .