Despite heavy investments in electric vehicles and autonomous driving, General Motors (GM -0.04%) is having no trouble churning out impressive profits. The company grew revenue by 25.1% year over year in the second quarter to $44.7 billion, and adjusted earnings per share soared 67.5% to $1.91.

Other metrics were equally impressive. Adjusted automotive free cash flow came in at $5.5 billion; average U.S. transaction price jumped $1,890 year-over-year to $52,248; and U.S. market share rose 0.7 percentage points. In response to these strong second-quarter results, which handily beat analyst estimates across the board, GM raised its guidance for the full year.

Adjusted earnings before interest and taxes are now expected between $12 billion and $14 billion, a $1 billion bump over the company's previous guidance range; adjusted automotive free cash flow should come in between $7 billion and $9 billion, up $1.5 billion from the old outlook; and adjusted earnings per share is now on track for a range of $7.15 to $8.15, compared with an old range of $6.35 to $7.35.

While GM stock has risen this year, it's still not too late to buy the stock.

Big trucks, small SUVs, and EVs

A big part of GM's success is tied to its truck business. Premium trucks are in high demand, and GM is taking full advantage. The company successfully sold customers on its off-road AT4 package for 70% of GMC Sierra HD sales, close to half of Sierra LD sales, and 74% of Canyon sales. Meanwhile, three-quarters of Chevrolet Tahoe and Suburban sales came with premium trims.

Going in the other direction, GM is having success winning over customers looking for smaller vehicles. The company's Chevrolet brand has reached a 25% market share in the small SUV segment, its best performance since 2007. The Chevrolet Trax more than doubled sales in the U.S., and about half of those sales came from customers switching from a non-GM brand.

While GM's gas-powered vehicles are still generating the vast majority of revenue and profit, the company is rapidly scaling its electric vehicle business. The company produced 50,000 EVs in the first half of the year in North America, and it's aiming to double that production rate in the second half. New EVs set to start production this year include the Chevrolet Silverado EV Work Truck, the Chevrolet Blazer EV, the Chevrolet Equinox EV, as well as a few other models.

A recent deal with Tesla to adopt that company's EV charging standard will greatly expand the charging network available to GM's EV customers. GM customers can start using Tesla's network of superchargers in early 2024, and other collaborations will expand the number of charging options further.

By 2025, GM is still targeting at least $50 billion in annual EV revenue and a production capacity of 1 million units in North America. The company also expects the EV business to be profitable by that year, with a mid-single-digit EBIT margin.

A long-term winner

GM is setting its sights on doubling annual revenue by 2030 in addition to expanding its profit margins thanks to new businesses and an increase in software revenue. If the company even gets within the ballpark of those goals, the stock could be in for an epic rally.

Based on the midpoint of GM's 2023 guidance range, the stock trades for just over 5 times earnings. The auto business is cyclical, and a recession would likely derail GM's financial performance temporarily. In other words, GM is not the kind of company where earnings will go up and to the right each and every year.

Still, it's hard to see GM stock as anything other than a bargain. If the economy does take a turn for the worse and put pressure on GM's bottom line, the company has a rock-solid balance sheet that will help it weather the storm. Cash and marketable securities excluding GM Financial totaled $27.5 billion at the end of the second quarter, while non-GM Financial debt stood at $16 billion.

The stock market has been pessimistic about GM for a very long time. While it's hard to say when the stock will earn a valuation that better reflects the company's profitability and growth prospects, buying and holding looks like a great idea for long-term investors.