WHAT a difference 15 months makes. On June 1st 2009 General Motors applied for Chapter 11 protection, triggering the largest industrial bankruptcy in American history. This week the carmaker filed papers with the Securities and Exchange Commission to pave the way for an initial public offering before the end of the year.

On August 12th the firm unveiled net earnings of $1.3 billion for the three months to June, its second quarterly profit in a row and its best since 2004. GM also announced that it had secured a $5 billion revolving credit line and that its chief executive, Ed Whitacre, would soon depart. The former boss of AT&T took over at GM only last December, but the bankers handling the IPO feared that, at 68, he might not be around for the long haul. His replacement will be another former telecoms executive, Dan Akerson.

GM's IPO is coming sooner than expected and perhaps sooner than the company would have wished. But it will serve some pressing needs. First, it is expected to raise $12 billion-16 billion (the first of several rounds of fund-raising). That will allow GM to start paying back some of the $50 billion it received from American and Canadian taxpayers. Second, the sale of shares will reduce the American government's 61% stake. GM is desperate to jettison the “Government Motors” stigma, which it believes is costing it sales. Finally, the IPO will help President Barack Obama, who is anxious to show voters that the rescue of GM and Chrysler, its smaller Detroit rival, has worked out better than anyone expected. The bail-out remains unpopular and congressional elections are only two-and-a-half months away.

Nobody can be sure what would have happened if GM and Chrysler had been allowed to go under. But rivals, including Ford, which managed by the skin of its teeth to avoid bankruptcy, feared that a collapsing GM would take down with it America's highly-integrated network of car-parts suppliers. That, in turn, would have threatened the whole car industry.

Some will accuse Mr Obama of declaring victory too soon. The anaemic recovery in the American car market since last year's trough of 10m sales may not be maintained. Hopes of sales rising to 12m vehicles this year now look optimistic; 11m-11.5m is more likely. The 16m-17m that was once deemed normal is now a distant memory. The Detroit firms' fortunes are even more closely linked to the general health of the economy than competitors'. Sales of highly profitable pickup trucks are tightly correlated with housing starts, while buoyant business travel boosts demand from car-rental firms.

Even with the economy subdued, however, all three Detroit carmakers are making profits. Ford, the healthiest, is still saddled with more than $27 billion of debt, but it is now generating plenty of cash. Its second quarter net earnings were $2.6 billion, its best performance for 12 years, which enabled it to pay off $7 billion of debt. All of its international operations are profitable. Its excellent products are gaining market share nearly everywhere. By the end of 2011, Ford expects its cash to exceed its debt. Earlier this month, Standard & Poor's upgraded its credit rating from B-minus to B-plus. Ford's chief executive, Alan Mulally, radiates quiet confidence.

Chrysler's performance has been shocking—in a good way. Last year the firm was assumed to be doomed. In the most recent quarter, it made a net loss of $172m but an operating profit of $183m. Max Warburton of BernsteinResearch reckons the firm may now be generating 4-5% margins, despite its clapped-out range of models. Bankruptcy helped. So has Fiat's Sergio Marchionne, who is overseeing its revival. Mr Warburton estimates that Chrysler has cut $7 billion of costs.

All three firms are showing admirable discipline. Inventories are low; discounts small. Detroit's old “push” model—factories churned out cars regardless of whether anyone wanted them—is a thing of the past. But there is still work to be done. Ford is in the best shape. It has a clear strategy, based on “global” cars that can be built and sold in every important market. Its management is stable; its products first-rate. Its two biggest challenges are reducing its debt and making up for lost time in China, where GM has done far better.

The biggest issue for Chrysler is whether its new vehicles, which will slowly start to arrive at the end of the year, are good enough. Mr Marchionne says that the first quarter of next year will be the moment of “almighty truth”. But although Chrysler's line-up is getting classier cabins and facelifts, there will be only a handful of genuinely new cars before Fiat-based models start to arrive after 2012. Sceptics believe that Chrysler has lost most of its product-development talent and question whether a small-car specialist like Fiat can give it the kind of vehicles it needs to win back market share in America, which accounts for 80% of its sales.

Fiat's 20% stake in Chrysler (which it received in exchange for management and technology) is due to rise to 35% in 2011 or 2012 on reaching some easily achievable milestones. It has an option to raise its share to 51%, allowing it to consolidate Chrysler in its accounts. Mr Marchionne is in no hurry to have an IPO, however, perhaps because he would then have to pay the full market price for the stock he will need to gain full control.

The prospects for GM are clearer. Labour contracts are fixed until 2015, while new cars, such as the Chevrolet Equinox crossover, are keeping downsized factories humming at near capacity. Three things should trouble investors, however. Having decided (rightly) to hold on to its European arm, Opel/Vauxhall, GM is committed to spending $4.6 billion to restructure this loss-making business. Another worry is GM's pension scheme, which is underfunded by $27 billion. And finally, the firm looks unstable at the top. Mr Whitacre replaced or shifted 12 of GM's top 13 executives. Now he too is leaving. If Mr Akerson, a tough egg, shakes things up again, fragile executive morale could plunge. GM's IPO will not be easy, but the fact that it is happening at all is remarkable.