God is capitalized when it functions as a name. In this use, God is a proper noun like any other name and does not take a definite or indefinite article. But in phrases like the Biblical god and a forgiving god, which do have articles, there’s no need to capitalize god because it is a common noun rather than a name—yet many religiously inclined writers still capitalize the word in these instances.
When the noun god is used generically, especially in reference to a non-Biblical god, it is not capitalized.
English speakers also traditionally capitalize the pronoun He in reference to God. This remains a common practice among people of faith, but it is by no means obligatory.
In phrases like for God’s sake, by God, and thank God, the word is capitalized because it generally refers to the god of the Bible and treats the word as a name.
For example, God is capitalized in these sentences because it names the Judeo-Christian god (note the lack of definite or indefinite article):
The notion that you believe in God has become synonymous with the notion that you hold things with a rigid, possibly violent, certainty. [Guardian]
He says God has planned a holocaust of judgment for America worse than any WMD. [Salon]
I was against abortion, divorce and homosexuality because God’s word said they were wrong. [Denver Post]
When the word refers to the Judeo-Christian god but does not name him directly, there is no logical or grammatical reason to capitalize it. Notwithstanding this, many writers still capitalize the word in these cases—for example:
Lionel found his God at Oxford in the 1950s, and his God has a name, which is “Fred”. [Independent]
A father is prepared to sacrifice h
is beloved son, but at the last moment his knife-wielding hand is stayed by a God who desires no such offering. [Boston Globe]
Capitalizing God in such instances gives the impression that the writer is a person of faith (though, to be fair, many publications impose this style choice on their writers regardless of faith).
And when god is used generically or in reference to any but the Judeo-Christian, monotheistic god, it is not capitalized:
Rock god Eric Clapton is caught airing his dirty laundry in public – at a self-service launderette. [Mirror]
The new trailer for Marvel’s upcoming superhero flick Thor gets laughs from the fish-out-of-water predicament of an ancient Nordic god. [Wired]
He towered over me, that great silvery hair giving him the proper bearing of a god. [New York Times]