As a song, "The Star Spangled Banner" was one of many patriotic songs of the era, some of which have still survived. Although it didn't have official status as the national anthem until 1931, generations of schoolchildren learned to sing it along with the other patriotic songs of the era. This is how the words "In God is our trust" entered the American psyche.
During the Civil War, both sides thought they had God on their side. Most combatants do. Lincoln gave recognition to "In God We Trust", but a variation of the words had been sung for decades before that whenever someone started singing "The Star Spangled Banner".
lol