It is from the Ganesha Purana. It was told to a king called Varenya by Lord Ganesha himself.
You can read it from this page.
Varenya said, ‘In the world of birth and death many difficulties
arise, and they are very hard to endure. Remover of obstacles, kindly
show me the path to liberation now. How can there be bondage in the
realization of You, Dviradnana. Declare to me that teaching by which I
will attain liberation, that yoga through which I will give up desire,
anger and the fear of death.’
Brahma said, “After having listened to this speech, Gajanana kindly
sat Varenya on a comfortable seat and placed his hand on his head.
Then he began to teach him the Ganesha Gita, casting away all his
doubts by presenting His universal form. As soon as he understood the
essence of the Gita from Ganesha’s instruction and having transferred
the kingdom to his ministers, he went to the forest. Filled with
detachment, the accomplished King meditated on Gajanana, fixed on
nothing else, and always preached the Gita. Just as water thrown into
water stays only as water, so he came to consist of Him by meditating
Also, there are many Gitas that are found in the Puranas. And, all of them preach more or less the same things. So, if you have read one of them, then you kind of already know what to find in the others.
For example, Iswara Gita (which is found in the Kurma Purana) is exactly the same as the Gita that is found in Mahabharata, with the only difference being that one is in the words of Parama Shiva while the other in those of Krishna.