The flag of São Tomé and Príncipe was adopted on November 5, 1975, a few months after the archipelago left Portuguese rule. The design came from Manuel Pinto da Costa, who became the country's first president.
Independence and the flag it produced
Independence arrived on July 12, 1975, near the end of the wave of decolonization that ran through Africa in the 1960s and 1970s. Like most of the new states of that decade, São Tomé and Príncipe wanted a flag that owed nothing to the colonial power, and the Pan-African colors were the obvious vocabulary to reach for.
The design has not been altered since.
Two islands, two stars
Three horizontal bands of green, yellow, and green, with a red triangle at the hoist and two black stars in the yellow band. The stars are the specific part: one for São Tomé, one for Príncipe.
Green is for the vegetation of the islands and their agricultural land. Yellow is for the sun and for cocoa, the country's main export and for a long time the backbone of its economy. Red is for the independence struggle and the people who died in it.
Where it is flown
The national flag is also the ensign. It flies on government buildings, at public events, and on national holidays, and it represents the country at official ceremonies and international gatherings, where the usual diplomatic rules about placement alongside other flags apply.
There are no official variants. Promotional material sometimes takes small liberties with the proportions or the shade of the colors, but the design itself does not change.
The Ghana resemblance
The flag looks a great deal like Ghana's, which uses the same green, yellow, and red. That is not coincidence so much as shared source material. Pan-Africanism supplied a common set of colors to states that became independent within a few years of each other, and a new flag in that palette read immediately as a statement of solidarity with the rest of the continent.
References
[1] Official Government of São Tomé and Príncipe - National Symbols (URL)