No, you don't have to cause the green fire to leap to another creature, as of the 2020 errata
The green-flame blade cantrip was updated when it was reprinted in Tasha's Cauldron of Everything (p. 107), and the version in the Sword Coast Adventurer's Guide (p. 143) received errata to match.
The relevant line of the green-flame blade spell description now reads:
On a hit, the target suffers the weapon attack’s normal effects, and
you can cause green fire to leap from the target to a different
creature of your choice that you can see within 5 feet of it.
The use of the word "can" indicates that the green fire does not have to leap to a second creature. Thus, if the only other creatures within 5 feet of the initial target are the caster and their allies (for instance), the caster can choose not to have the green fire leap at all after the damage to the initial target.
Even pre-errata, designer intent indicated that the caster didn't have to target another creature
Pre-errata, it was not directly stated in the spell description whether you had to target yourself with the secondary damage if no other creature was in range, or if you could choose not to have the green fire leap to anybody at all.
However, rules designer Jeremy Crawford unofficially answered this question in a tweet from November 2015:
What does the leap effect of green-flame blade do if there are no hostile targets nearby? Does it jump to allies?
The intent is that you can choose no one. If you can't see, you can't choose anyway, and the flame halts
While the wording might have suggested that the spell has to target another creature, Crawford clearly stated that that was not the intent; you could choose not to target anyone if there was no desired secondary target in range. The errata has brought this aspect of the spell in line with the stated intent.
This makes sense to me. Given that if the attack hits, the caster could choose what creature the green fire leapt to, it makes sense that the caster could use the same control over targeting to prevent the green fire from jumping to any creature at all (e.g. by having it fizzle harmlessly against the ground, or extinguishing itself).