get while the getting is good
To cease, end, or give up (doing) something before it becomes too difficult or the consequences become too severe. There are some reports that the market is about to take a dive, so I reckon we should get out while the getting is good. Listen, kid, there's no way you can win this fight, so why don't you get out while the getting is good?
get (out) while the gettin(g)'s good
and get (out) while the goin(g)'s goodto leave while it is still safe or possible to do so. I could tell that it was time for me to get while the gettin's good. I told her she should get out while the gain's good.