At the Battle of Gettysburg in July , it helped defend the left flank of the Union army .