The hymn was originally part of The Psalms of David Imitated in the Language of the New Testament, published by Watts in 1719. In this book he paraphrased in Christian verse the entire psalter with the exception of twelve Psalms which he felt were unsuited for Christian usage.
The hymn is often sung as part of the remembrance day service in Canada and festive occasions in England.
The hymn tune "St. Anne" (common metre 86.86) to which the text is most often sung was composed by William Croft in 1708 whilst he was the organist of the church of St Anne, Soho: hence the name of the tune. It first appeared anonymously in the Supplement to the New Version of the Psalms, 6th edition in 1708. It was originally intended to be used with a version of Psalm 62. It was not until sometime later when set to Watts' text that the tune gained recognition.
Later composers subsequently incorporated the tune in their own works. For example, George Handel used the tune in an anthem entitled, "O Praise the Lord". J. S. Bach's Fugue in E-flat major BWV 552 is often called the "St. Anne" in the English speaking world, because of the similarity of its subject to the first line of the hymn tune, though there is some debate as to whether Bach used the actual tune after hearing it, or coincidentally created himself the very similar tune used as the fugual theme. Young Bach's inspirator and mentor Dieterich Buxtehude, churchadministrator and organist of St.Mary's in Lübeck in North-Germany, used the same first line of the hymn tune as theme for the (first) fugue of his Praeludium-pedaliter in E-major for organ.
Arthur Sullivan uses the tune in the first and last sections of his Festival Te Deum, first in a relatively standard setting, but eventually pairing it with a military march accompaniment. The American composer Carl Ruggles (1876–1971) used the text in his last composition, "Exaltation" (for Brass, Chorus, and Organ) in 1958, in memory of his wife Charlotte who had died the previous year. The hymn and words are also featured in Vaughan Williams's anthem "Lord, thou hast been our refuge", using both the Book of Common Prayer's words and those of Watts. Brother Colin Smith also arranged a setting of this hymn.