Oooh I know this one, let me refresh my memory via wikipedia really fast.
Okay, so the tune itself is predates both songs by a good deal, it seems to be an old folk hymn called "Say, Brothers will you Meet Us" that was pretty widespread by the 1850s via oral tradition and revivalist camp meetings. At some point it's chorus which had the line "We'll shout and give him Glory" mutated into "Glory, Glory Hallelujah".
Anecdotally, "John Brown's Body" version came about from a group of union soldiers having fun with the fact that they had a Sergeant also named John Brown (No relation). To quote an account From George Kimball in 1890
"We had a jovial Scotchman in the battalion, named John Brown ⦠and as he happened to bear the identical name of the old hero of Harper's Ferry, he became at once the butt of his comrades. If he made his appearance a few minutes late among the working squad, or was a little tardy in falling into the company line, he was sure to be greeted with such expressions as "Come, old fellow, you ought to be at it if you are going to help us free the slaves"; or, "This can't be John Brownāwhy, John Brown is dead." And then some wag would add, in a solemn, drawling tone, as if it were his purpose to give particular emphasis to the fact that John Brown was really, actually dead: "Yes, yes, poor old John Brown is dead; his body lies mouldering in the grave."
These jokes were eventually set to the tune of "Say Brothers", producing the song "John Brown's Body", which spread through union ranks, but was considered somewhat course and unseemly. During the war, a woman named Julia Ward Howe heard soldiers singing the tune and decided to write new words to create a more dignified soldier's anthem, which became the Battle Hymn of the Republic.