General Motors is promising to go green by making all of its global operations and vehicles carbon neutral by 2040, including selling only zero-emission models by 2035.

The pledge is a bold embrace by the automaker of emission-reduction goals set by California. The state is one of the largest markets for vehicles in the U.S. and announced plans in September to ban sales of gasoline-powered cars and trucks by 2035. GM’s target for achieving company-wide carbon neutrality is 10 years ahead of rival Ford’s goal.

The company’s stock rose as much as 7.4 percent on the news.

GM’s initiative is part of Chief Executive Officer Mary Barra’s strategy to take on Tesla Inc.’s leadership in electric vehicles and change the Detroit company’s image as a builder of gas-guzzling, carbon-spewing trucks and SUVs. Barra already has committed GM to spending $27 billion to build 30 electric vehicles by 2025.

“General Motors is joining governments and companies around the globe working to establish a safer, greener and better world,” Barra said in a statement. “We encourage others to follow suit and make a significant impact on our industry and on the economy as a whole.”

GM will have to convert every model it sells to run on battery power or possibly hydrogen to meet its target. It aims to lower the price of some electric vehicles to make them accessible to more new-car buyers.

“Our focus will be offering zero-emission vehicles across a range of price points,” Dane Parker, GM’s chief sustainability officer, said in a call with reporters. “We’re going to need to have products that appeal to all of our consumers, products they want and products that they can afford.”

A big challenge for GM is staying profitable as it transitions to lower-margin electric vehicles. Currently the gas-guzzling pickups and SUVs it’s known for make up the majority of GM’s income. Company President Mark Reuss has said the cost of GM’s Ultium battery pack is coming down and its electric vehicles will be profitable.

UBS said in a report published last year that most global carmakers will be able to phase out their carbon emissions by 2040.

“We believe the transportation sector can be almost entirely decarbonized by 2040,” the report said. “Why? New technologies have breakthroughs enabling them to start providing value at a reasonable cost, and saving energy has a feel good factor attached to it.”

GM plans to use renewable energy for all of its plants and buildings globally by 2035. That’s five years faster than the company previously targeted.

Barra’s move shows how the company’s strategic plans have been shifting rapidly. Four months ago when California Gov. Gavin Newsom announced his ban on gasoline-fueled cars starting in 2035, Ford was quick to issue a statement praising the step. GM and Fiat Chrysler Automobiles NV, now part of newly-merged Stellantis NV, deferred comment to an industry trade association, which said more needed to be done to increase consumer demand for electric vehicles.

At the time, GM was still supporting former President Donald Trump’s lawsuit to eliminate California’s exemption from federal emissions rules, which allowed the state to pass its own tougher restrictions. After Trump lost the election, GM withdrew its support. Ford, Honda, Volkswagen and BMW had sided with California earlier.

Fred Krupp, president of the Environmental Defense Fund, said he has been talking to Barra for about five years and in that time, the automaker’s views on carbon emissions have evolved, gathering pace more recently.

“This is for real,” Krupp said in a phone interview. “Mary Barra is betting the company that this is the next big transition for the industry.”