The other answer seems to miss an important historical context here, also described on Wikipedia:
The organization was founded to facilitate shared macroeconomic initiatives by its members in response to the collapse of the exchange rate 1971, during the time of the Nixon shock, the 1970s energy crisis and the ensuing recession.
The G6 was formed in 1975 consisting of the France, (West) Germany, Italy, Japan, the UK, and the US; USSR and China were excluded at that time for perhaps obvious reasons. Economically, China in the 1970s was also nothing like economic China today. Canada was quickly added (G7), and then much later Russia (post-USSR collapse and with a growing economic relationship with Europe) to form the G8.
Russia is not considered an advanced country, either, by the IMF, and yet was part of the G8 until being suspended over the occupation/annexation of Crimea, so it seems incorrect to say that the IMF distinction is actually relevant: this is a club by invitation-only, not a prize obtained by meeting some specific criteria.
The G(#) remains mostly a Western economic meeting, with the inclusion of Japan being as much a geographical outlier as the exclusion of China, yet making sense based on shared economic interests from the 1970s.